org.h2.store.fs
Class FileSystem

java.lang.Object
  extended by org.h2.store.fs.FileSystem
Direct Known Subclasses:
FileSystemDisk, FileSystemMemory, FileSystemSplit, FileSystemZip

public abstract class FileSystem
extends java.lang.Object

The file system is a storage abstraction.


Field Summary
static java.lang.String PREFIX_MEMORY
          The prefix used for an in-memory file system.
static java.lang.String PREFIX_MEMORY_LZF
          The prefix used for a compressed in-memory file system.
static java.lang.String PREFIX_NIO
          The prefix used for the NIO FileChannel file system.
static java.lang.String PREFIX_NIO_MAPPED
          The prefix used for the NIO (memory mapped) file system.
static java.lang.String PREFIX_SPLIT
          The prefix used to split large files (required for a FAT32 because it only support files up to 2 GB).
static java.lang.String PREFIX_ZIP
          The prefix used for a read-only zip-file based file system.
 
Constructor Summary
FileSystem()
           
 
Method Summary
protected  boolean accepts(java.lang.String fileName)
          Check if the file system is responsible for this file name.
abstract  boolean canWrite(java.lang.String fileName)
          Check if the file is writable.
abstract  void copy(java.lang.String original, java.lang.String copy)
          Copy a file from one directory to another, or to another file.
abstract  void createDirs(java.lang.String fileName)
          Create all required directories that are required for this file.
abstract  boolean createNewFile(java.lang.String fileName)
          Create a new file.
abstract  java.lang.String createTempFile(java.lang.String prefix, java.lang.String suffix, boolean deleteOnExit, boolean inTempDir)
          Create a new temporary file.
abstract  void delete(java.lang.String fileName)
          Delete a file.
abstract  void deleteRecursive(java.lang.String directory, boolean tryOnly)
          Delete a directory or file and all subdirectories and files.
abstract  boolean exists(java.lang.String fileName)
          Checks if a file exists.
abstract  boolean fileStartsWith(java.lang.String fileName, java.lang.String prefix)
          Check if a file starts with a given prefix.
abstract  java.lang.String getAbsolutePath(java.lang.String fileName)
          Get the absolute file name.
abstract  java.lang.String getFileName(java.lang.String name)
          Get the file name (without directory part).
static FileSystem getInstance(java.lang.String fileName)
          Get the file system object.
abstract  long getLastModified(java.lang.String fileName)
          Get the last modified date of a file
abstract  java.lang.String getParent(java.lang.String fileName)
          Get the parent directory of a file or directory.
abstract  boolean isAbsolute(java.lang.String fileName)
          Check if the file name includes a path.
abstract  boolean isDirectory(java.lang.String fileName)
          Check if it is a file or a directory.
abstract  boolean isReadOnly(java.lang.String fileName)
          Check if a file is read-only.
abstract  long length(java.lang.String fileName)
          Get the length of a file.
abstract  java.lang.String[] listFiles(java.lang.String directory)
          List the files in the given directory.
 void mkdirs(java.lang.String directoryName)
          Create all required directories.
abstract  java.lang.String normalize(java.lang.String fileName)
          Normalize a file name.
abstract  java.io.InputStream openFileInputStream(java.lang.String fileName)
          Create an input stream to read from the file.
abstract  FileObject openFileObject(java.lang.String fileName, java.lang.String mode)
          Open a random access file object.
abstract  java.io.OutputStream openFileOutputStream(java.lang.String fileName, boolean append)
          Create an output stream to write into the file.
static void register(FileSystem service)
          Register a file system.
abstract  void rename(java.lang.String oldName, java.lang.String newName)
          Rename a file if this is allowed.
abstract  boolean tryDelete(java.lang.String fileName)
          Try to delete a file.
static void unregister(FileSystem service)
          Unregister a file system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFIX_MEMORY

public static final java.lang.String PREFIX_MEMORY
The prefix used for an in-memory file system.

See Also:
Constant Field Values

PREFIX_MEMORY_LZF

public static final java.lang.String PREFIX_MEMORY_LZF
The prefix used for a compressed in-memory file system.

See Also:
Constant Field Values

PREFIX_ZIP

public static final java.lang.String PREFIX_ZIP
The prefix used for a read-only zip-file based file system.

See Also:
Constant Field Values

PREFIX_SPLIT

public static final java.lang.String PREFIX_SPLIT
The prefix used to split large files (required for a FAT32 because it only support files up to 2 GB).

See Also:
Constant Field Values

PREFIX_NIO

public static final java.lang.String PREFIX_NIO
The prefix used for the NIO FileChannel file system.

See Also:
Constant Field Values

PREFIX_NIO_MAPPED

public static final java.lang.String PREFIX_NIO_MAPPED
The prefix used for the NIO (memory mapped) file system.

See Also:
Constant Field Values
Constructor Detail

FileSystem

public FileSystem()
Method Detail

getInstance

public static FileSystem getInstance(java.lang.String fileName)
Get the file system object.

Parameters:
fileName - the file name or prefix
Returns:
the file system

register

public static void register(FileSystem service)
Register a file system.

Parameters:
service - the file system

unregister

public static void unregister(FileSystem service)
Unregister a file system.

Parameters:
service - the file system

accepts

protected boolean accepts(java.lang.String fileName)
Check if the file system is responsible for this file name.

Parameters:
fileName - the file name
Returns:
true if it is

length

public abstract long length(java.lang.String fileName)
Get the length of a file.

Parameters:
fileName - the file name
Returns:
the length in bytes

rename

public abstract void rename(java.lang.String oldName,
                            java.lang.String newName)
                     throws java.sql.SQLException
Rename a file if this is allowed.

Parameters:
oldName - the old fully qualified file name
newName - the new fully qualified file name
Throws:
java.sql.SQLException

createNewFile

public abstract boolean createNewFile(java.lang.String fileName)
                               throws java.sql.SQLException
Create a new file.

Parameters:
fileName - the file name
Returns:
true if creating was successful
Throws:
java.sql.SQLException

exists

public abstract boolean exists(java.lang.String fileName)
Checks if a file exists.

Parameters:
fileName - the file name
Returns:
true if it exists

delete

public abstract void delete(java.lang.String fileName)
                     throws java.sql.SQLException
Delete a file.

Parameters:
fileName - the file name
Throws:
java.sql.SQLException

tryDelete

public abstract boolean tryDelete(java.lang.String fileName)
Try to delete a file.

Parameters:
fileName - the file name
Returns:
true if it could be deleted

createTempFile

public abstract java.lang.String createTempFile(java.lang.String prefix,
                                                java.lang.String suffix,
                                                boolean deleteOnExit,
                                                boolean inTempDir)
                                         throws java.io.IOException
Create a new temporary file.

Parameters:
prefix - the prefix of the file name (including directory name if required)
suffix - the suffix
deleteOnExit - if the file should be deleted when the virtual machine exists
inTempDir - if the file should be stored in the temporary directory
Returns:
the name of the created file
Throws:
java.io.IOException

listFiles

public abstract java.lang.String[] listFiles(java.lang.String directory)
                                      throws java.sql.SQLException
List the files in the given directory.

Parameters:
directory - the directory
Returns:
the list of fully qualified file names
Throws:
java.sql.SQLException

deleteRecursive

public abstract void deleteRecursive(java.lang.String directory,
                                     boolean tryOnly)
                              throws java.sql.SQLException
Delete a directory or file and all subdirectories and files.

Parameters:
directory - the directory
tryOnly - whether errors should be ignored
Throws:
java.sql.SQLException

isReadOnly

public abstract boolean isReadOnly(java.lang.String fileName)
Check if a file is read-only.

Parameters:
fileName - the file name
Returns:
if it is read only

normalize

public abstract java.lang.String normalize(java.lang.String fileName)
                                    throws java.sql.SQLException
Normalize a file name.

Parameters:
fileName - the file name
Returns:
the normalized file name
Throws:
java.sql.SQLException

getParent

public abstract java.lang.String getParent(java.lang.String fileName)
Get the parent directory of a file or directory.

Parameters:
fileName - the file or directory name
Returns:
the parent directory name

isDirectory

public abstract boolean isDirectory(java.lang.String fileName)
Check if it is a file or a directory.

Parameters:
fileName - the file or directory name
Returns:
true if it is a directory

isAbsolute

public abstract boolean isAbsolute(java.lang.String fileName)
Check if the file name includes a path.

Parameters:
fileName - the file name
Returns:
if the file name is absolute

getAbsolutePath

public abstract java.lang.String getAbsolutePath(java.lang.String fileName)
Get the absolute file name.

Parameters:
fileName - the file name
Returns:
the absolute file name

getLastModified

public abstract long getLastModified(java.lang.String fileName)
Get the last modified date of a file

Parameters:
fileName - the file name
Returns:
the last modified date

canWrite

public abstract boolean canWrite(java.lang.String fileName)
Check if the file is writable.

Parameters:
fileName - the file name
Returns:
if the file is writable

copy

public abstract void copy(java.lang.String original,
                          java.lang.String copy)
                   throws java.sql.SQLException
Copy a file from one directory to another, or to another file.

Parameters:
original - the original file name
copy - the file name of the copy
Throws:
java.sql.SQLException

mkdirs

public void mkdirs(java.lang.String directoryName)
            throws java.sql.SQLException
Create all required directories.

Parameters:
directoryName - the directory name
Throws:
java.sql.SQLException

createDirs

public abstract void createDirs(java.lang.String fileName)
                         throws java.sql.SQLException
Create all required directories that are required for this file.

Parameters:
fileName - the file name (not directory name)
Throws:
java.sql.SQLException

getFileName

public abstract java.lang.String getFileName(java.lang.String name)
                                      throws java.sql.SQLException
Get the file name (without directory part).

Parameters:
name - the directory and file name
Returns:
just the file name
Throws:
java.sql.SQLException

fileStartsWith

public abstract boolean fileStartsWith(java.lang.String fileName,
                                       java.lang.String prefix)
Check if a file starts with a given prefix.

Parameters:
fileName - the complete file name
prefix - the prefix
Returns:
true if it starts with the prefix

openFileOutputStream

public abstract java.io.OutputStream openFileOutputStream(java.lang.String fileName,
                                                          boolean append)
                                                   throws java.sql.SQLException
Create an output stream to write into the file.

Parameters:
fileName - the file name
append - if true, the file will grow, if false, the file will be truncated first
Returns:
the output stream
Throws:
java.sql.SQLException

openFileObject

public abstract FileObject openFileObject(java.lang.String fileName,
                                          java.lang.String mode)
                                   throws java.io.IOException
Open a random access file object.

Parameters:
fileName - the file name
mode - the access mode. Supported are r, rw, rws, rwd
Returns:
the file object
Throws:
java.io.IOException

openFileInputStream

public abstract java.io.InputStream openFileInputStream(java.lang.String fileName)
                                                 throws java.io.IOException
Create an input stream to read from the file.

Parameters:
fileName - the file name
Returns:
the input stream
Throws:
java.io.IOException