Class VirtualDir


  • public abstract class VirtualDir
    extends Object
    A read-only directory that can either be a directory in the file system or a ZIP-file. Files having '.gz' extensions are automatically decompressed.
    Since:
    Ceres 0.11
    • Constructor Detail

      • VirtualDir

        public VirtualDir()
    • Method Detail

      • getBasePath

        public abstract String getBasePath()
        Returns:
        The base path name of the directory.
      • getBaseFile

        public abstract File getBaseFile()
        Returns:
        The File object of the directory.
      • getReader

        public Reader getReader​(String path)
                         throws IOException
        Opens a reader for the given relative path.
        Parameters:
        path - The relative file path.
        Returns:
        A reader for the specified relative path.
        Throws:
        IOException - If the file does not exist or if it can't be opened for reading.
      • getInputStream

        public abstract InputStream getInputStream​(String path)
                                            throws IOException
        Opens an input stream for the given relative file path. Files having '.gz' extensions are automatically decompressed.
        Parameters:
        path - The relative file path.
        Returns:
        An input stream for the specified relative path.
        Throws:
        IOException - If the file does not exist or if it can't be opened for reading.
      • getFile

        public abstract File getFile​(String path)
                              throws IOException
        Gets the file for the given relative path.
        Parameters:
        path - The relative file or directory path.
        Returns:
        Gets the file or directory for the specified file path.
        Throws:
        IOException - If the file or directory does not exist or if it can't be extracted from a ZIP-file.
      • list

        public abstract String[] list​(String path)
                               throws IOException
        Returns an array of strings naming the files and directories in the directory denoted by the given relative directory path.

        There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

        Parameters:
        path - The relative directory path.
        Returns:
        An array of strings naming the files and directories in the directory denoted by the given relative directory path. The array will be empty if the directory is empty.
        Throws:
        IOException - If the directory given by the relative path does not exists.
      • exists

        public abstract boolean exists​(String path)
      • listAllFiles

        public abstract String[] listAllFiles()
                                       throws IOException
        Returns an array of strings naming the relative directory path of all file names.

        There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

        Returns:
        An array of strings naming the relative directory path and filename to all files. The array will be empty if the directory is empty.
        Throws:
        IOException - If an I/O error is thrown when accessing the virtual dir.
      • close

        public abstract void close()
        Closes access to this virtual directory.
      • create

        public static VirtualDir create​(File file)
        Creates an instance of a virtual directory object from a given directory or ZIP-file.
        Parameters:
        file - A directory or a ZIP-file.
        Returns:
        The virtual directory instance, or null if file is not a directory or a ZIP-file or the ZIP-file could not be opened for read access..
      • isCompressed

        public abstract boolean isCompressed()
      • isArchive

        public abstract boolean isArchive()
      • deleteFileTree

        public static void deleteFileTree​(File treeRoot)
        Deletes the directory treeRoot and all the content recursively.
        Parameters:
        treeRoot - directory to be deleted