org.h2.store.fs
Class FileSystemDisk

java.lang.Object
  extended by org.h2.store.fs.FileSystem
      extended by org.h2.store.fs.FileSystemDisk
Direct Known Subclasses:
FileSystemDiskNio

public class FileSystemDisk
extends FileSystem

This file system stores files on disk. This is the most common file system.


Constructor Summary
protected FileSystemDisk()
           
 
Method Summary
protected  boolean accepts(java.lang.String fileName)
          Check if the file system is responsible for this file name.
 boolean canWrite(java.lang.String fileName)
          Check if the file is writable.
 void copy(java.lang.String original, java.lang.String copy)
          Copy a file from one directory to another, or to another file.
 void createDirs(java.lang.String fileName)
          Create all required directories that are required for this file.
 boolean createNewFile(java.lang.String fileName)
          Create a new file.
 java.lang.String createTempFile(java.lang.String name, java.lang.String suffix, boolean deleteOnExit, boolean inTempDir)
          Create a new temporary file.
 void delete(java.lang.String fileName)
          Delete a file.
 void deleteRecursive(java.lang.String fileName, boolean tryOnly)
          Delete a directory or file and all subdirectories and files.
 boolean exists(java.lang.String fileName)
          Checks if a file exists.
static java.lang.String expandUserHomeDirectory(java.lang.String fileName)
          Expand '~' to the user home directory.
 boolean fileStartsWith(java.lang.String fileName, java.lang.String prefix)
          Check if a file starts with a given prefix.
protected  void freeMemoryAndFinalize()
          Call the garbage collection and run finalization.
 java.lang.String getAbsolutePath(java.lang.String fileName)
          Get the absolute file name.
 java.lang.String getFileName(java.lang.String name)
          Get the file name (without directory part).
static FileSystemDisk getInstance()
           
 long getLastModified(java.lang.String fileName)
          Get the last modified date of a file
 java.lang.String getParent(java.lang.String fileName)
          Get the parent directory of a file or directory.
 boolean isAbsolute(java.lang.String fileName)
          Check if the file name includes a path.
 boolean isDirectory(java.lang.String fileName)
          Check if it is a file or a directory.
 boolean isReadOnly(java.lang.String fileName)
          Check if a file is read-only.
 long length(java.lang.String fileName)
          Get the length of a file.
 java.lang.String[] listFiles(java.lang.String path)
          List the files in the given directory.
 java.lang.String normalize(java.lang.String fileName)
          Normalize a file name.
 java.io.InputStream openFileInputStream(java.lang.String fileName)
          Create an input stream to read from the file.
 FileObject openFileObject(java.lang.String fileName, java.lang.String mode)
          Open a random access file object.
 java.io.OutputStream openFileOutputStream(java.lang.String fileName, boolean append)
          Create an output stream to write into the file.
 void rename(java.lang.String oldName, java.lang.String newName)
          Rename a file if this is allowed.
 boolean setReadOnly(java.lang.String fileName)
          Disable the ability to write.
protected  void trace(java.lang.String method, java.lang.String fileName, java.lang.Object o)
          Print a trace message if tracing is enabled.
protected  java.lang.String translateFileName(java.lang.String fileName)
          Translate the file name to the native format.
 boolean tryDelete(java.lang.String fileName)
          Try to delete a file.
 
Methods inherited from class org.h2.store.fs.FileSystem
getInstance, getNextTempFileNamePart, mkdirs, register, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemDisk

protected FileSystemDisk()
Method Detail

getInstance

public static FileSystemDisk getInstance()

length

public long length(java.lang.String fileName)
Description copied from class: FileSystem
Get the length of a file.

Specified by:
length in class FileSystem
Parameters:
fileName - the file name
Returns:
the length in bytes

translateFileName

protected java.lang.String translateFileName(java.lang.String fileName)
Translate the file name to the native format. This will expand the home directory (~).

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

expandUserHomeDirectory

public static java.lang.String expandUserHomeDirectory(java.lang.String fileName)
Expand '~' to the user home directory. It is only be expanded if the ~ stands alone, or is followed by / or \.

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

rename

public void rename(java.lang.String oldName,
                   java.lang.String newName)
Description copied from class: FileSystem
Rename a file if this is allowed.

Specified by:
rename in class FileSystem
Parameters:
oldName - the old fully qualified file name
newName - the new fully qualified file name

trace

protected void trace(java.lang.String method,
                     java.lang.String fileName,
                     java.lang.Object o)
Print a trace message if tracing is enabled.

Parameters:
method - the method
fileName - the file name
o - the object

createNewFile

public boolean createNewFile(java.lang.String fileName)
Description copied from class: FileSystem
Create a new file.

Specified by:
createNewFile in class FileSystem
Parameters:
fileName - the file name
Returns:
true if creating was successful

exists

public boolean exists(java.lang.String fileName)
Description copied from class: FileSystem
Checks if a file exists.

Specified by:
exists in class FileSystem
Parameters:
fileName - the file name
Returns:
true if it exists

delete

public void delete(java.lang.String fileName)
Description copied from class: FileSystem
Delete a file.

Specified by:
delete in class FileSystem
Parameters:
fileName - the file name

tryDelete

public boolean tryDelete(java.lang.String fileName)
Description copied from class: FileSystem
Try to delete a file.

Specified by:
tryDelete in class FileSystem
Parameters:
fileName - the file name
Returns:
true if it could be deleted

createTempFile

public java.lang.String createTempFile(java.lang.String name,
                                       java.lang.String suffix,
                                       boolean deleteOnExit,
                                       boolean inTempDir)
                                throws java.io.IOException
Description copied from class: FileSystem
Create a new temporary file.

Overrides:
createTempFile in class FileSystem
Parameters:
name - 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 java.lang.String[] listFiles(java.lang.String path)
Description copied from class: FileSystem
List the files in the given directory.

Specified by:
listFiles in class FileSystem
Parameters:
path - the directory
Returns:
the list of fully qualified file names

deleteRecursive

public void deleteRecursive(java.lang.String fileName,
                            boolean tryOnly)
Description copied from class: FileSystem
Delete a directory or file and all subdirectories and files.

Specified by:
deleteRecursive in class FileSystem
Parameters:
fileName - the directory
tryOnly - whether errors should be ignored

isReadOnly

public boolean isReadOnly(java.lang.String fileName)
Description copied from class: FileSystem
Check if a file is read-only.

Specified by:
isReadOnly in class FileSystem
Parameters:
fileName - the file name
Returns:
if it is read only

setReadOnly

public boolean setReadOnly(java.lang.String fileName)
Description copied from class: FileSystem
Disable the ability to write.

Specified by:
setReadOnly in class FileSystem
Parameters:
fileName - the file name
Returns:
true if the call was successful

normalize

public java.lang.String normalize(java.lang.String fileName)
Description copied from class: FileSystem
Normalize a file name.

Specified by:
normalize in class FileSystem
Parameters:
fileName - the file name
Returns:
the normalized file name

getParent

public java.lang.String getParent(java.lang.String fileName)
Description copied from class: FileSystem
Get the parent directory of a file or directory.

Specified by:
getParent in class FileSystem
Parameters:
fileName - the file or directory name
Returns:
the parent directory name

isDirectory

public boolean isDirectory(java.lang.String fileName)
Description copied from class: FileSystem
Check if it is a file or a directory.

Specified by:
isDirectory in class FileSystem
Parameters:
fileName - the file or directory name
Returns:
true if it is a directory

isAbsolute

public boolean isAbsolute(java.lang.String fileName)
Description copied from class: FileSystem
Check if the file name includes a path.

Specified by:
isAbsolute in class FileSystem
Parameters:
fileName - the file name
Returns:
if the file name is absolute

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String fileName)
Description copied from class: FileSystem
Get the absolute file name.

Specified by:
getAbsolutePath in class FileSystem
Parameters:
fileName - the file name
Returns:
the absolute file name

getLastModified

public long getLastModified(java.lang.String fileName)
Description copied from class: FileSystem
Get the last modified date of a file

Specified by:
getLastModified in class FileSystem
Parameters:
fileName - the file name
Returns:
the last modified date

canWrite

public boolean canWrite(java.lang.String fileName)
Description copied from class: FileSystem
Check if the file is writable.

Specified by:
canWrite in class FileSystem
Parameters:
fileName - the file name
Returns:
if the file is writable

copy

public void copy(java.lang.String original,
                 java.lang.String copy)
Description copied from class: FileSystem
Copy a file from one directory to another, or to another file.

Specified by:
copy in class FileSystem
Parameters:
original - the original file name
copy - the file name of the copy

createDirs

public void createDirs(java.lang.String fileName)
Description copied from class: FileSystem
Create all required directories that are required for this file.

Specified by:
createDirs in class FileSystem
Parameters:
fileName - the file name (not directory name)

getFileName

public java.lang.String getFileName(java.lang.String name)
Description copied from class: FileSystem
Get the file name (without directory part).

Specified by:
getFileName in class FileSystem
Parameters:
name - the directory and file name
Returns:
just the file name

fileStartsWith

public boolean fileStartsWith(java.lang.String fileName,
                              java.lang.String prefix)
Description copied from class: FileSystem
Check if a file starts with a given prefix.

Specified by:
fileStartsWith in class FileSystem
Parameters:
fileName - the complete file name
prefix - the prefix
Returns:
true if it starts with the prefix

openFileOutputStream

public java.io.OutputStream openFileOutputStream(java.lang.String fileName,
                                                 boolean append)
Description copied from class: FileSystem
Create an output stream to write into the file.

Specified by:
openFileOutputStream in class FileSystem
Parameters:
fileName - the file name
append - if true, the file will grow, if false, the file will be truncated first
Returns:
the output stream

openFileInputStream

public java.io.InputStream openFileInputStream(java.lang.String fileName)
                                        throws java.io.IOException
Description copied from class: FileSystem
Create an input stream to read from the file.

Specified by:
openFileInputStream in class FileSystem
Parameters:
fileName - the file name
Returns:
the input stream
Throws:
java.io.IOException

freeMemoryAndFinalize

protected void freeMemoryAndFinalize()
Call the garbage collection and run finalization. This close all files that were not closed, and are no longer referenced.


openFileObject

public FileObject openFileObject(java.lang.String fileName,
                                 java.lang.String mode)
                          throws java.io.IOException
Description copied from class: FileSystem
Open a random access file object.

Specified by:
openFileObject in class FileSystem
Parameters:
fileName - the file name
mode - the access mode. Supported are r, rw, rws, rwd
Returns:
the file object
Throws:
java.io.IOException

accepts

protected boolean accepts(java.lang.String fileName)
Description copied from class: FileSystem
Check if the file system is responsible for this file name.

Specified by:
accepts in class FileSystem
Parameters:
fileName - the file name
Returns:
true if it is