Package org.codehaus.cargo.daemon.file
Class FileManager
- java.lang.Object
-
- org.codehaus.cargo.daemon.file.FileManager
-
public class FileManager extends Object
File manager to deal with files and directories in the daemon workspace.
-
-
Constructor Summary
Constructors Constructor Description FileManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
copy(String filename, OutputStream out, long offset, long size)
Copies the given file to the output stream continously, i.e. not stop when end of file is reached, but rather wait for additional data to be appended to the file.void
copyHeader(InputStream in, OutputStream out)
Copies the inputstream to the output stream, and keeps the output stream open.void
deleteWorkspaceDirectory(String handleId)
Delete workspace directory.void
deleteWorkspaceFiles()
Delete temporary files.boolean
existsFile(String handleId, String filename)
Check if filename exists in the workspace.String
getCargoHomeDirectory()
Get the cargo home directory.String
getConfigurationDirectory()
Get the configuration home directory.String
getConfigurationDirectory(String handleId)
Get the configuration home directory for a container.InputStream
getFileInputStream(String filename)
Get the file input streamlong
getFileSize(String filePath)
Get the size of a file.String
getFileURL(String filename)
Get the URL for a filename in the workspace.String
getHandleDatabaseFile()
Gets the file path of the handle record file.String
getInstallDirectory()
Get the install directory.String
getLogDirectory()
Get the log directory.String
getLogDirectory(String handleId)
Get the log directory for a container.String
getLogFile(String handleId, String filename)
Get the log file for a container.String
getWorkspaceDirectory()
Get the workspace directory.String
getWorkspaceDirectory(String handleId)
Get the workspace directory for a container.HandleDatabase
loadHandleDatabase()
String
resolveConfigurationPath(String handleId, String relativePath)
Resolves a path relative to the configuration directory to an absolute path.String
resolveWorkspacePath(String handleId, String relativePath)
Resolves a path relative to the workspace directory to an absolute path.String
saveFile(String relativeFile, InputStream inputStream)
Saves the input stream to a file, relative to the workspace directory.String
saveFile(String handleId, String relativeFile, InputStream inputStream)
Saves the input stream to a file, relative to the workspace directory of a container.String
saveFile(String handleId, String relativeDirectory, String relativeFile, InputStream inputStream)
Saves the input stream to a file, relative to the workspace directory of a container and a given directory.void
saveHandleDatabase(HandleDatabase database)
Save handle database to disk.void
saveRequestProperties(String handleId, Properties properties)
Saves the start request properties to a file to the workspace directory, so that it can later be started again.
-
-
-
Method Detail
-
getCargoHomeDirectory
public String getCargoHomeDirectory()
Get the cargo home directory.- Returns:
- the cargo home directory
-
getWorkspaceDirectory
public String getWorkspaceDirectory()
Get the workspace directory.- Returns:
- the workspace directory
-
getInstallDirectory
public String getInstallDirectory()
Get the install directory.- Returns:
- the install directory
-
getHandleDatabaseFile
public String getHandleDatabaseFile()
Gets the file path of the handle record file. The handle record file keeps track of the handle id's and if they should be automatically started.- Returns:
- the file path to handle record file
-
loadHandleDatabase
public HandleDatabase loadHandleDatabase() throws IOException
- Returns:
- The handle database loaded from disk.
- Throws:
IOException
- if error occurs
-
saveHandleDatabase
public void saveHandleDatabase(HandleDatabase database) throws IOException
Save handle database to disk.- Parameters:
database
- The handle database to save.- Throws:
IOException
- if error occurs.
-
saveRequestProperties
public void saveRequestProperties(String handleId, Properties properties) throws IOException
Saves the start request properties to a file to the workspace directory, so that it can later be started again.- Parameters:
handleId
- The handle identifier of a containerproperties
- The start request properties- Throws:
IOException
- if exception happens
-
getWorkspaceDirectory
public String getWorkspaceDirectory(String handleId)
Get the workspace directory for a container.- Parameters:
handleId
- The handle identifier of a container- Returns:
- the workspace directory
-
getConfigurationDirectory
public String getConfigurationDirectory()
Get the configuration home directory.- Returns:
- the configuration home directory
-
getLogDirectory
public String getLogDirectory()
Get the log directory.- Returns:
- the log directory
-
getLogDirectory
public String getLogDirectory(String handleId)
Get the log directory for a container.- Parameters:
handleId
- The handle identifier of a container- Returns:
- the log directory for a container
-
getLogFile
public String getLogFile(String handleId, String filename)
Get the log file for a container.- Parameters:
handleId
- The handle identifier of a containerfilename
- The log file name- Returns:
- the log directory for a container
-
getConfigurationDirectory
public String getConfigurationDirectory(String handleId)
Get the configuration home directory for a container.- Parameters:
handleId
- The handle identifier of a container- Returns:
- the default configuration home directory for a container
-
deleteWorkspaceFiles
public void deleteWorkspaceFiles()
Delete temporary files.
-
deleteWorkspaceDirectory
public void deleteWorkspaceDirectory(String handleId)
Delete workspace directory.- Parameters:
handleId
- The handle identifier of a container
-
saveFile
public String saveFile(String relativeFile, InputStream inputStream) throws IOException
Saves the input stream to a file, relative to the workspace directory.- Parameters:
relativeFile
- The relative filenameinputStream
- The inputstream containing the file contents- Returns:
- path to the saved file
- Throws:
IOException
- if exception happens
-
saveFile
public String saveFile(String handleId, String relativeFile, InputStream inputStream) throws IOException
Saves the input stream to a file, relative to the workspace directory of a container.- Parameters:
handleId
- The handle identifier of a containerrelativeFile
- The relative filenameinputStream
- The inputstream containing the file contents- Returns:
- path to the saved file
- Throws:
IOException
- if exception happens
-
saveFile
public String saveFile(String handleId, String relativeDirectory, String relativeFile, InputStream inputStream) throws IOException
Saves the input stream to a file, relative to the workspace directory of a container and a given directory.- Parameters:
handleId
- The handle identifier of a containerrelativeDirectory
- The relative directoryrelativeFile
- The relative filenameinputStream
- The inputstream containing the file contents- Returns:
- path to the saved file
- Throws:
IOException
- if exception happens
-
existsFile
public boolean existsFile(String handleId, String filename)
Check if filename exists in the workspace.- Parameters:
handleId
- The handle identifier of a containerfilename
- The file to check- Returns:
- true if file exists
-
getFileURL
public String getFileURL(String filename)
Get the URL for a filename in the workspace.- Parameters:
filename
- The filename to construct URL for- Returns:
- the URL for the filename
-
getFileInputStream
public InputStream getFileInputStream(String filename)
Get the file input stream- Parameters:
filename
- The filename to get input stream from- Returns:
- the input stream
-
copyHeader
public void copyHeader(InputStream in, OutputStream out) throws IOException
Copies the inputstream to the output stream, and keeps the output stream open.- Parameters:
in
- The soruce input streamout
- The destination output stream- Throws:
IOException
- if error happens
-
getFileSize
public long getFileSize(String filePath)
Get the size of a file.- Parameters:
filePath
- The file- Returns:
- The size
-
copy
public long copy(String filename, OutputStream out, long offset, long size) throws IOException, InterruptedException
Copies the given file to the output stream continously, i.e. not stop when end of file is reached, but rather wait for additional data to be appended to the file.- Parameters:
filename
- The file to copyout
- The destination output streamoffset
- The starting offset to read fromsize
- The size to read- Returns:
- The last position of the file
- Throws:
IOException
- if error happensInterruptedException
- if error happens when sleeping
-
resolveWorkspacePath
public String resolveWorkspacePath(String handleId, String relativePath)
Resolves a path relative to the workspace directory to an absolute path.- Parameters:
handleId
- The handle id.relativePath
- The path relative to the workspace.- Returns:
- The absolute file path.
-
resolveConfigurationPath
public String resolveConfigurationPath(String handleId, String relativePath)
Resolves a path relative to the configuration directory to an absolute path.- Parameters:
handleId
- The handle id.relativePath
- The path relative to the configuration.- Returns:
- The absolute file path.
-
-