Interface FileSystem

  • All Known Implementing Classes:
    BasedFileSystem, LocalFileSystem

    public interface FileSystem
    The FileSystem interface is an abstraction of a virtual file system. The similarities of its method names with with the methods of the java.io.File class are intentional.
    Implementations of this interface expose a file system-like resource. File system-like resources include WebDAV-enabled servers, local file systems, and so forth.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SEPARATOR
      File separator
      static char SEPARATOR_CHAR
      File separator character
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Close the file system.
      void createFolder​(java.lang.String folderPath)
      Creates the folder named by this path, including any necessary but nonexistent parent folders.
      void deleteFile​(java.lang.String filePath)
      Deletes the file denoted by this path.
      void deleteFolder​(java.lang.String folderPath)
      Deletes the folder denoted by this path.
      boolean exists​(java.lang.String path)
      Tests whether the file system entry denoted by this path exists.
      java.io.InputStream getInputStream​(java.lang.String filePath)
      Returns an input stream of the contents of the file denoted by this path.
      java.io.OutputStream getOutputStream​(java.lang.String filePath)
      Returns an output stream for writing bytes to the file denoted by this path.
      boolean hasChildren​(java.lang.String path)
      Tests whether the file system entry denoted by this path has child entries.
      void init()
      Initialize the file system
      boolean isFile​(java.lang.String path)
      Tests whether the file system entry denoted by this path exists and is a file.
      boolean isFolder​(java.lang.String path)
      Tests whether the file system entry denoted by this path exists and is a folder.
      long lastModified​(java.lang.String path)
      Returns the time that the file system entry denoted by this path was last modified.
      long length​(java.lang.String filePath)
      Returns the length of the file denoted by this path.
      java.lang.String[] list​(java.lang.String folderPath)
      Returns an array of strings naming the files and folders in the folder denoted by this path.
      java.lang.String[] listFiles​(java.lang.String folderPath)
      Returns an array of strings naming the files in the folder denoted by this path.
      java.lang.String[] listFolders​(java.lang.String folderPath)
      Returns an array of strings naming the folders in the folder denoted by this path.
    • Method Detail

      • getInputStream

        java.io.InputStream getInputStream​(java.lang.String filePath)
                                    throws FileSystemException
        Returns an input stream of the contents of the file denoted by this path.
        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

        java.io.OutputStream getOutputStream​(java.lang.String filePath)
                                      throws FileSystemException
        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.
        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
      • createFolder

        void createFolder​(java.lang.String folderPath)
                   throws FileSystemException
        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.
        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.
      • exists

        boolean exists​(java.lang.String path)
                throws FileSystemException
        Tests whether the file system entry denoted by this path exists.
        Parameters:
        path - the path of a file system entry.
        Returns:
        true if the file system entry at path exists; false otherwise.
        Throws:
        FileSystemException
      • isFile

        boolean isFile​(java.lang.String path)
                throws FileSystemException
        Tests whether the file system entry denoted by this path exists and is a file.
        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

        boolean isFolder​(java.lang.String path)
                  throws FileSystemException
        Tests whether the file system entry denoted by this path exists and is a folder.
        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
      • hasChildren

        boolean hasChildren​(java.lang.String path)
                     throws FileSystemException
        Tests whether the file system entry denoted by this path has child entries.
        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
      • length

        long length​(java.lang.String filePath)
             throws FileSystemException
        Returns the length of the file denoted by this path.
        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.
      • lastModified

        long lastModified​(java.lang.String path)
                   throws FileSystemException
        Returns the time that the file system entry denoted by this path was last modified.
        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.
      • list

        java.lang.String[] list​(java.lang.String folderPath)
                         throws FileSystemException
        Returns an array of strings naming the files and folders in the folder denoted by this path.
        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.
        Throws:
        FileSystemException - if this path does not denote a folder or if another error occurs.
      • listFiles

        java.lang.String[] listFiles​(java.lang.String folderPath)
                              throws FileSystemException
        Returns an array of strings naming the files in the folder denoted by this path.
        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.
        Throws:
        FileSystemException - if this path does not denote a folder or if another error occurs.
      • listFolders

        java.lang.String[] listFolders​(java.lang.String folderPath)
                                throws FileSystemException
        Returns an array of strings naming the folders in the folder denoted by this path.
        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.
        Throws:
        FileSystemException - if this path does not denote a folder or if another error occurs.
      • deleteFile

        void deleteFile​(java.lang.String filePath)
                 throws FileSystemException
        Deletes the file denoted by this path.
        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

        void deleteFolder​(java.lang.String folderPath)
                   throws FileSystemException
        Deletes the folder denoted by this path. Any contents of this folder (folders and files) will be deleted recursively.
        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.