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.


Constructor Summary
FileSystem()
           
 
Method Summary
protected abstract  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.
 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
protected  java.lang.String getNextTempFileNamePart(boolean newRandom)
          Get the next temporary file name part (the part in the middle).
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 setReadOnly(java.lang.String fileName)
          Disable the ability to write.
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
 

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 abstract 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)
Rename a file if this is allowed.

Parameters:
oldName - the old fully qualified file name
newName - the new fully qualified file name

createNewFile

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

Parameters:
fileName - the file name
Returns:
true if creating was successful

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)
Delete a file.

Parameters:
fileName - the file name

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

listFiles

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

Parameters:
directory - the directory
Returns:
the list of fully qualified file names

deleteRecursive

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

Parameters:
directory - the directory
tryOnly - whether errors should be ignored

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)
Normalize a file name.

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

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)
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

mkdirs

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

Parameters:
directoryName - the directory name

createDirs

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

Parameters:
fileName - the file name (not directory name)

getFileName

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

Parameters:
name - the directory and file name
Returns:
just the file name

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)
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

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

setReadOnly

public abstract boolean setReadOnly(java.lang.String fileName)
Disable the ability to write.

Parameters:
fileName - the file name
Returns:
true if the call was successful

getNextTempFileNamePart

protected java.lang.String getNextTempFileNamePart(boolean newRandom)
Get the next temporary file name part (the part in the middle).

Parameters:
newRandom - if the random part of the filename should change
Returns:
the file name part

createTempFile

public 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