Class MemoryFileSystem

  • All Implemented Interfaces:
    FileSystem

    public class MemoryFileSystem
    extends Object
    implements FileSystem
    An in-memory file system implementation.
    • Constructor Detail

      • MemoryFileSystem

        public MemoryFileSystem()
    • Method Detail

      • close

        public void close()
        Description copied from interface: FileSystem
        Close the file system. After calling this method, the file system is no longer accessible.
        Specified by:
        close in interface FileSystem
      • createFolder

        public void createFolder​(String folderPath)
                          throws FileSystemException
        Description copied from interface: FileSystem
        Creates the folder named by this path, including any necessary but nonexistent parent folders. Note that if this operation fails it may have succeeded in creating some of the necessary parent folders.
        Specified by:
        createFolder in interface FileSystem
        Parameters:
        folderPath - the path of the folder to be created.
        Throws:
        FileSystemException - if a file system entry denoted by path already exists or if another error occurs.
      • deleteFile

        public void deleteFile​(String filePath)
                        throws FileSystemException
        Description copied from interface: FileSystem
        Deletes the file denoted by this path.
        Specified by:
        deleteFile in interface FileSystem
        Parameters:
        filePath - the path of the file to be deleted.
        Throws:
        FileSystemException - if this path does not denote a file or if another error occurs.
      • deleteFolder

        public void deleteFolder​(String folderPath)
                          throws FileSystemException
        Description copied from interface: FileSystem
        Deletes the folder denoted by this path. Any contents of this folder (folders and files) will be deleted recursively.
        Specified by:
        deleteFolder in interface FileSystem
        Parameters:
        folderPath - the path of the folder to be deleted.
        Throws:
        FileSystemException - if this path does not denote a folder or if another error occurs.
      • exists

        public boolean exists​(String path)
                       throws FileSystemException
        Description copied from interface: FileSystem
        Tests whether the file system entry denoted by this path exists.
        Specified by:
        exists in interface FileSystem
        Parameters:
        path - the path of a file system entry.
        Returns:
        true if the file system entry at path exists; false otherwise.
        Throws:
        FileSystemException
      • getInputStream

        public InputStream getInputStream​(String filePath)
                                   throws FileSystemException
        Description copied from interface: FileSystem
        Returns an input stream of the contents of the file denoted by this path.
        Specified by:
        getInputStream in interface FileSystem
        Parameters:
        filePath - the path of the file.
        Returns:
        an input stream of the contents of the file.
        Throws:
        FileSystemException - if the file does not exist or if it cannot be read from
      • getOutputStream

        public OutputStream getOutputStream​(String filePath)
                                     throws FileSystemException
        Description copied from interface: FileSystem
        Returns an output stream for writing bytes to the file denoted by this path. The file will be created if it doesn't exist. If the file exists, its contents will be overwritten.
        Specified by:
        getOutputStream in interface FileSystem
        Parameters:
        filePath - the path of the file.
        Returns:
        an output stream for writing bytes to the file.
        Throws:
        FileSystemException - if the file cannot be written to or created
      • hasChildren

        public boolean hasChildren​(String path)
                            throws FileSystemException
        Description copied from interface: FileSystem
        Tests whether the file system entry denoted by this path has child entries.
        Specified by:
        hasChildren in interface FileSystem
        Parameters:
        path - the path of a file system entry.
        Returns:
        true if the file system entry at path has child entries; false otherwise.
        Throws:
        FileSystemException
      • init

        public void init()
        Description copied from interface: FileSystem
        Initialize the file system
        Specified by:
        init in interface FileSystem
      • isFile

        public boolean isFile​(String path)
                       throws FileSystemException
        Description copied from interface: FileSystem
        Tests whether the file system entry denoted by this path exists and is a file.
        Specified by:
        isFile in interface FileSystem
        Parameters:
        path - the path of a file system entry.
        Returns:
        true if the file system entry at path is a file; false otherwise.
        Throws:
        FileSystemException
      • isFolder

        public boolean isFolder​(String path)
                         throws FileSystemException
        Description copied from interface: FileSystem
        Tests whether the file system entry denoted by this path exists and is a folder.
        Specified by:
        isFolder in interface FileSystem
        Parameters:
        path - the path of a file system entry.
        Returns:
        true if the file system entry at path is a folder; false otherwise.
        Throws:
        FileSystemException
      • lastModified

        public long lastModified​(String path)
                          throws FileSystemException
        Description copied from interface: FileSystem
        Returns the time that the file system entry denoted by this path was last modified.
        Specified by:
        lastModified in interface FileSystem
        Parameters:
        path - the path of a file system entry.
        Returns:
        A long value representing the time the file system entry was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the modification time can't be determined.
        Throws:
        FileSystemException - if the file system entry does not exist.
      • length

        public long length​(String filePath)
                    throws FileSystemException
        Description copied from interface: FileSystem
        Returns the length of the file denoted by this path.
        Specified by:
        length in interface FileSystem
        Parameters:
        filePath - the path of the file.
        Returns:
        The length, in bytes, of the file denoted by this path, or -1L if the length can't be determined.
        Throws:
        FileSystemException - if the path does not denote an existing file.
      • list

        public String[] list​(String folderPath)
        Description copied from interface: FileSystem
        Returns an array of strings naming the files and folders in the folder denoted by this path.
        Specified by:
        list in interface FileSystem
        Parameters:
        folderPath - the path of the folder whose contents is to be listed.
        Returns:
        an array of strings naming the files and folders in the folder denoted by this path.
      • listFiles

        public String[] listFiles​(String folderPath)
        Description copied from interface: FileSystem
        Returns an array of strings naming the files in the folder denoted by this path.
        Specified by:
        listFiles in interface FileSystem
        Parameters:
        folderPath - the path of the folder whose contents is to be listed.
        Returns:
        an array of strings naming the files in the folder denoted by this path.
      • listFolders

        public String[] listFolders​(String folderPath)
        Description copied from interface: FileSystem
        Returns an array of strings naming the folders in the folder denoted by this path.
        Specified by:
        listFolders in interface FileSystem
        Parameters:
        folderPath - the path of the folder whose contents is to be listed.
        Returns:
        an array of strings naming the folders in the folder denoted by this path.