Class FileManager


  • public class FileManager
    extends Object
    File manager to deal with files and directories in the daemon workspace.
    • Constructor Detail

      • FileManager

        public FileManager()
    • 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
      • 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 container
        properties - 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 container
        filename - 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)
        Saves the input stream to a file, relative to the workspace directory.
        Parameters:
        relativeFile - The relative filename
        inputStream - The inputstream containing the file contents
        Returns:
        path to the saved file
      • saveFile

        public String saveFile​(String handleId,
                               String relativeFile,
                               InputStream inputStream)
        Saves the input stream to a file, relative to the workspace directory of a container.
        Parameters:
        handleId - The handle identifier of a container
        relativeFile - The relative filename
        inputStream - The inputstream containing the file contents
        Returns:
        path to the saved file
      • saveFile

        public 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.
        Parameters:
        handleId - The handle identifier of a container
        relativeDirectory - The relative directory
        relativeFile - The relative filename
        inputStream - The inputstream containing the file contents
        Returns:
        path to the saved file
      • existsFile

        public boolean existsFile​(String filename)
        Check if filename exists in the workspace.
        Parameters:
        filename - 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 stream
        out - 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 copy
        out - The destination output stream
        offset - The starting offset to read from
        size - The size to read
        Returns:
        The last position of the file
        Throws:
        IOException - if error happens
        InterruptedException - 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.