Package com.bc.ceres.core
Class VirtualDir
- java.lang.Object
-
- com.bc.ceres.core.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 Summary
Constructors Constructor Description VirtualDir()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close()
Closes access to this virtual directory.static VirtualDir
create(File file)
Creates an instance of a virtual directory object from a given directory or ZIP-file.static File
createUniqueTempDir()
static void
deleteFileTree(File treeRoot)
Deletes the directorytreeRoot
and all the content recursively.abstract boolean
exists(String path)
protected void
finalize()
abstract File
getBaseFile()
abstract String
getBasePath()
abstract File
getFile(String path)
Gets the file for the given relative path.abstract InputStream
getInputStream(String path)
Opens an input stream for the given relative file path.Reader
getReader(String path)
Opens a reader for the given relative path.File
getTempDir()
abstract boolean
isArchive()
abstract boolean
isCompressed()
abstract String[]
list(String path)
Returns an array of strings naming the files and directories in the directory denoted by the given relative directory path.abstract String[]
listAllFiles()
Returns an array of strings naming the relative directory path of all file names.
-
-
-
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
iffile
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()
-
getTempDir
public File getTempDir() throws IOException
- Throws:
IOException
-
finalize
protected void finalize() throws Throwable
-
deleteFileTree
public static void deleteFileTree(File treeRoot)
Deletes the directorytreeRoot
and all the content recursively.- Parameters:
treeRoot
- directory to be deleted
-
createUniqueTempDir
public static File createUniqueTempDir() throws IOException
- Throws:
IOException
-
-