org.h2.test.utils
Class FilePathUnstable

java.lang.Object
  extended by org.h2.store.fs.FilePath
      extended by org.h2.store.fs.FilePathWrapper
          extended by org.h2.test.utils.FilePathUnstable

public class FilePathUnstable
extends FilePathWrapper

An unstable file system. It is used to simulate file system problems (for example out of disk space).


Field Summary
 
Fields inherited from class org.h2.store.fs.FilePath
name
 
Constructor Summary
FilePathUnstable()
           
 
Method Summary
 boolean canWrite()
          Check if the file is writable.
 void createDirectory()
          Create a directory (all required parent directories already exist).
 boolean createFile()
          Create a new file.
 FilePath createTempFile(java.lang.String suffix, boolean deleteOnExit, boolean inTempDir)
          Create a new temporary file.
 void delete()
          Delete a file or directory if it exists.
 boolean exists()
          Checks if a file exists.
 int getDiskFullCount()
           
 java.lang.String getName()
          Get the file or directory name (the last element of the path).
 FilePath getParent()
          Get the parent directory of a file or directory.
 java.lang.String getScheme()
          Get the scheme (prefix) for this file provider.
 boolean isAbsolute()
          Check if the file name includes a path.
 boolean isDirectory()
          Check if it is a file or a directory.
 long lastModified()
          Get the last modified date of a file
 void moveTo(FilePath newName)
          Rename a file if this is allowed.
 java.util.List<FilePath> newDirectoryStream()
          List the files and directories in the given directory.
 java.io.InputStream newInputStream()
          Create an input stream to read from the file.
 java.io.OutputStream newOutputStream(boolean append)
          Create an output stream to write into the file.
 java.nio.channels.FileChannel open(java.lang.String mode)
          Open a random access file object.
static FilePathUnstable register()
          Register the file system.
 void setDiskFullCount(int count)
           
 boolean setReadOnly()
          Disable the ability to write.
 long size()
          Get the size of a file in bytes
 FilePath toRealPath()
          Normalize a file name.
 
Methods inherited from class org.h2.store.fs.FilePathWrapper
getBase, getPath, getPrefix, unwrap, unwrap, wrap
 
Methods inherited from class org.h2.store.fs.FilePath
get, getNextTempFileNamePart, register, toString, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilePathUnstable

public FilePathUnstable()
Method Detail

register

public static FilePathUnstable register()
Register the file system.

Returns:
the instance

createDirectory

public void createDirectory()
Description copied from class: FilePath
Create a directory (all required parent directories already exist).

Overrides:
createDirectory in class FilePathWrapper

createFile

public boolean createFile()
Description copied from class: FilePath
Create a new file.

Overrides:
createFile in class FilePathWrapper
Returns:
true if creating was successful

delete

public void delete()
Description copied from class: FilePath
Delete a file or directory if it exists. Directories may only be deleted if they are empty.

Overrides:
delete in class FilePathWrapper

exists

public boolean exists()
Description copied from class: FilePath
Checks if a file exists.

Overrides:
exists in class FilePathWrapper
Returns:
true if it exists

getName

public java.lang.String getName()
Description copied from class: FilePath
Get the file or directory name (the last element of the path).

Overrides:
getName in class FilePath
Returns:
the last element of the path

lastModified

public long lastModified()
Description copied from class: FilePath
Get the last modified date of a file

Overrides:
lastModified in class FilePathWrapper
Returns:
the last modified date

getParent

public FilePath getParent()
Description copied from class: FilePath
Get the parent directory of a file or directory.

Overrides:
getParent in class FilePathWrapper
Returns:
the parent directory name

isAbsolute

public boolean isAbsolute()
Description copied from class: FilePath
Check if the file name includes a path.

Overrides:
isAbsolute in class FilePathWrapper
Returns:
if the file name is absolute

isDirectory

public boolean isDirectory()
Description copied from class: FilePath
Check if it is a file or a directory.

Overrides:
isDirectory in class FilePathWrapper
Returns:
true if it is a directory

canWrite

public boolean canWrite()
Description copied from class: FilePath
Check if the file is writable.

Overrides:
canWrite in class FilePathWrapper
Returns:
if the file is writable

setReadOnly

public boolean setReadOnly()
Description copied from class: FilePath
Disable the ability to write.

Overrides:
setReadOnly in class FilePathWrapper
Returns:
true if the call was successful

size

public long size()
Description copied from class: FilePath
Get the size of a file in bytes

Overrides:
size in class FilePathWrapper
Returns:
the size in bytes

newDirectoryStream

public java.util.List<FilePath> newDirectoryStream()
Description copied from class: FilePath
List the files and directories in the given directory.

Overrides:
newDirectoryStream in class FilePathWrapper
Returns:
the list of fully qualified file names

toRealPath

public FilePath toRealPath()
Description copied from class: FilePath
Normalize a file name.

Overrides:
toRealPath in class FilePathWrapper
Returns:
the normalized file name

newInputStream

public java.io.InputStream newInputStream()
                                   throws java.io.IOException
Description copied from class: FilePath
Create an input stream to read from the file.

Overrides:
newInputStream in class FilePathWrapper
Returns:
the input stream
Throws:
java.io.IOException

open

public java.nio.channels.FileChannel open(java.lang.String mode)
                                   throws java.io.IOException
Description copied from class: FilePath
Open a random access file object.

Overrides:
open in class FilePathWrapper
Parameters:
mode - the access mode. Supported are r, rw, rws, rwd
Returns:
the file object
Throws:
java.io.IOException

newOutputStream

public java.io.OutputStream newOutputStream(boolean append)
Description copied from class: FilePath
Create an output stream to write into the file.

Overrides:
newOutputStream in class FilePathWrapper
Parameters:
append - if true, the file will grow, if false, the file will be truncated first
Returns:
the output stream

moveTo

public void moveTo(FilePath newName)
Description copied from class: FilePath
Rename a file if this is allowed.

Overrides:
moveTo in class FilePathWrapper
Parameters:
newName - the new fully qualified file name

createTempFile

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

Overrides:
createTempFile in class FilePathWrapper
Parameters:
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

setDiskFullCount

public void setDiskFullCount(int count)

getDiskFullCount

public int getDiskFullCount()

getScheme

public java.lang.String getScheme()
Description copied from class: FilePath
Get the scheme (prefix) for this file provider. This is similar to java.nio.file.spi.FileSystemProvider.getScheme.

Specified by:
getScheme in class FilePath
Returns:
the scheme