Top Description Fields Constructors Methods
org.h2.store.fs

public abstract Class FilePath

extends Object
Class Inheritance
Known Direct Subclasses
org.h2.store.fs.FilePathWrapper, org.h2.store.fs.disk.FilePathDisk, org.h2.store.fs.mem.FilePathMem, org.h2.store.fs.niomem.FilePathNioMem, org.h2.store.fs.zip.FilePathZip
Imports
java.io.IOException, .InputStream, .OutputStream, java.nio.channels.Channels, .FileChannel, java.util.List, java.util.concurrent.ConcurrentHashMap, org.h2.store.fs.disk.FilePathDisk, org.h2.util.MathUtils

A path to a file. It similar to the Java 7 java.nio.file.Path, but simpler, and works with older versions of Java. It also implements the relevant methods found in java.nio.file.FileSystem and FileSystems

Field Summary

Modifier and TypeField and Description
private static final FilePath
public String
name

The complete path (which may be absolute or relative, depending on the file system).

private static final ConcurrentHashMap<String, FilePath>
private static String
tempRandom

The prefix for temporary files.

private static long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract boolean

Returns:

if the file is writable
canWrite
()

Check if the file is writable.

public abstract void
createDirectory()

Create a directory (all required parent directories already exist).

public abstract boolean

Returns:

true if creating was successful
createFile
()

Create a new file.

public FilePath

Returns:

the name of the created file
createTempFile
(String
the suffix
suffix
,
boolean
if the file should be stored in the temporary directory
inTempDir
)

Create a new temporary file.

public abstract void
delete()

Delete a file or directory if it exists.

public abstract boolean

Returns:

true if it exists
exists
()

Checks if a file exists.

public static FilePath

Returns:

the file path object
get
(String
the path
path
)

Get the file path object for the given path.

public String

Returns:

the last element of the path
getName
()

Get the file or directory name (the last element of the path).

private static synchronized String

Returns:

the file name part
getNextTempFileNamePart
(boolean
if the random part of the filename should change
newRandom
)

Get the next temporary file name part (the part in the middle).

public abstract FilePath

Returns:

the parent directory name
getParent
()

Get the parent directory of a file or directory.

public abstract FilePath

Returns:

the file path object
getPath
(String
the path
path
)

Convert a file to a path.

public abstract String

Returns:

the scheme
getScheme
()

Get the scheme (prefix) for this file provider.

public abstract boolean

Returns:

if the file name is absolute
isAbsolute
()

Check if the file name includes a path.

public abstract boolean

Returns:

true if it is a directory
isDirectory
()

Check if it is a file or a directory.

public abstract boolean

Returns:

true if it is a regular file
isRegularFile
()

Check if it is a regular file.

public abstract long

Returns:

the last modified date
lastModified
()

Get the last modified date of a file

public abstract void
moveTo(FilePath
the new fully qualified file name
newName
,
boolean
whether the move should be atomic, and the target file should be replaced if it exists and replacing is possible
atomicReplace
)

Rename a file if this is allowed.

public abstract List<FilePath>

Returns:

the list of fully qualified file names
newDirectoryStream
()

List the files and directories in the given directory.

public static OutputStream

Returns:

the output stream
newFileChannelOutputStream
(FileChannel
the file channel
channel
,
boolean
true for append mode, false for truncate and overwrite
append
)

Create a new output stream from the channel.

public InputStream

Returns:

the input stream
newInputStream
()

Create an input stream to read from the file.

public OutputStream

Returns:

the output stream
newOutputStream
(boolean
if true, the file will grow, if false, the file will be truncated first
append
)

Create an output stream to write into the file.

public abstract FileChannel

Returns:

the file object
open
(String
the access mode. Supported are r, rw, rws, rwd
mode
)

Open a random access file object.

public static void
register(FilePath
the file provider
provider
)

Register a file provider.

public abstract boolean

Returns:

true if the call was successful
setReadOnly
()

Disable the ability to write.

public abstract long

Returns:

the size in bytes
size
()

Get the size of a file in bytes

public abstract FilePath

Returns:

the normalized file name
toRealPath
()

Normalize a file name.

public String

Returns:

the path as a string
toString
()

Overrides java.lang.Object.toString.

Get the string representation.

public static void
unregister(FilePath
the file provider
provider
)

Unregister a file provider.

public FilePath

Returns:

the unwrapped path
unwrap
()

Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

defaultProviderback to summary
private static final FilePath defaultProvider
nameback to summary
public String name

The complete path (which may be absolute or relative, depending on the file system).

providersback to summary
private static final ConcurrentHashMap<String, FilePath> providers
tempRandomback to summary
private static String tempRandom

The prefix for temporary files.

tempSequenceback to summary
private static long tempSequence

Constructor Detail

FilePathback to summary
public FilePath()

Method Detail

canWriteback to summary
public abstract boolean canWrite()

Check if the file is writable.

Returns:boolean

if the file is writable

createDirectoryback to summary
public abstract void createDirectory()

Create a directory (all required parent directories already exist).

createFileback to summary
public abstract boolean createFile()

Create a new file.

Returns:boolean

true if creating was successful

createTempFileback to summary
public FilePath createTempFile(String suffix, boolean inTempDir) throws IOException

Create a new temporary file.

Parameters
suffix:String

the suffix

inTempDir:boolean

if the file should be stored in the temporary directory

Returns:FilePath

the name of the created file

Annotations
@SuppressWarnings:unused
Exceptions
IOException:
on failure
deleteback to summary
public abstract void delete()

Delete a file or directory if it exists. Directories may only be deleted if they are empty.

existsback to summary
public abstract boolean exists()

Checks if a file exists.

Returns:boolean

true if it exists

getback to summary
public static FilePath get(String path)

Get the file path object for the given path. Windows-style '\' is replaced with '/'.

Parameters
path:String

the path

Returns:FilePath

the file path object

getNameback to summary
public String getName()

Get the file or directory name (the last element of the path).

Returns:String

the last element of the path

getNextTempFileNamePartback to summary
private static synchronized String getNextTempFileNamePart(boolean newRandom)

Get the next temporary file name part (the part in the middle).

Parameters
newRandom:boolean

if the random part of the filename should change

Returns:String

the file name part

getParentback to summary
public abstract FilePath getParent()

Get the parent directory of a file or directory.

Returns:FilePath

the parent directory name

getPathback to summary
public abstract FilePath getPath(String path)

Convert a file to a path. This is similar to java.nio.file.spi.FileSystemProvider.getPath, but may return an object even if the scheme doesn't match in case of the default file provider.

Parameters
path:String

the path

Returns:FilePath

the file path object

getSchemeback to summary
public abstract String getScheme()

Get the scheme (prefix) for this file provider. This is similar to java.nio.file.spi.FileSystemProvider.getScheme.

Returns:String

the scheme

isAbsoluteback to summary
public abstract boolean isAbsolute()

Check if the file name includes a path.

Returns:boolean

if the file name is absolute

isDirectoryback to summary
public abstract boolean isDirectory()

Check if it is a file or a directory.

Returns:boolean

true if it is a directory

isRegularFileback to summary
public abstract boolean isRegularFile()

Check if it is a regular file.

Returns:boolean

true if it is a regular file

lastModifiedback to summary
public abstract long lastModified()

Get the last modified date of a file

Returns:long

the last modified date

moveToback to summary
public abstract void moveTo(FilePath newName, boolean atomicReplace)

Rename a file if this is allowed.

Parameters
newName:FilePath

the new fully qualified file name

atomicReplace:boolean

whether the move should be atomic, and the target file should be replaced if it exists and replacing is possible

newDirectoryStreamback to summary
public abstract List<FilePath> newDirectoryStream()

List the files and directories in the given directory.

Returns:List<FilePath>

the list of fully qualified file names

newFileChannelOutputStreamback to summary
public static OutputStream newFileChannelOutputStream(FileChannel channel, boolean append) throws IOException

Create a new output stream from the channel.

Parameters
channel:FileChannel

the file channel

append:boolean

true for append mode, false for truncate and overwrite

Returns:OutputStream

the output stream

Exceptions
IOException:
on I/O exception
newInputStreamback to summary
public InputStream newInputStream() throws IOException

Create an input stream to read from the file.

Returns:InputStream

the input stream

Exceptions
IOException:
If an I/O error occurs
newOutputStreamback to summary
public OutputStream newOutputStream(boolean append) throws IOException

Create an output stream to write into the file.

Parameters
append:boolean

if true, the file will grow, if false, the file will be truncated first

Returns:OutputStream

the output stream

Exceptions
IOException:
If an I/O error occurs
openback to summary
public abstract FileChannel open(String mode) throws IOException

Open a random access file object.

Parameters
mode:String

the access mode. Supported are r, rw, rws, rwd

Returns:FileChannel

the file object

Exceptions
IOException:
If an I/O error occurs
registerback to summary
public static void register(FilePath provider)

Register a file provider.

Parameters
provider:FilePath

the file provider

setReadOnlyback to summary
public abstract boolean setReadOnly()

Disable the ability to write.

Returns:boolean

true if the call was successful

sizeback to summary
public abstract long size()

Get the size of a file in bytes

Returns:long

the size in bytes

toRealPathback to summary
public abstract FilePath toRealPath()

Normalize a file name.

Returns:FilePath

the normalized file name

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get the string representation. The returned string can be used to construct a new object.

Returns:String

the path as a string

Annotations
@Override
unregisterback to summary
public static void unregister(FilePath provider)

Unregister a file provider.

Parameters
provider:FilePath

the file provider

unwrapback to summary
public FilePath unwrap()

Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).

Returns:FilePath

the unwrapped path