Package org.h2.store.fs
Class FilePath
java.lang.Object
org.h2.store.fs.FilePath
- Direct Known Subclasses:
FilePathDisk,FilePathMem,FilePathNioMem,FilePathWrapper,FilePathZip,FilePathZip2
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancanWrite()Check if the file is writable.abstract voidCreate a directory (all required parent directories already exist).abstract booleanCreate a new file.createTempFile(String suffix, boolean inTempDir) Create a new temporary file.abstract voiddelete()Delete a file or directory if it exists.abstract booleanexists()Checks if a file exists.static FilePathGet the file path object for the given path.getName()Get the file or directory name (the last element of the path).abstract FilePathGet the parent directory of a file or directory.abstract FilePathConvert a file to a path.abstract StringGet the scheme (prefix) for this file provider.abstract booleanCheck if the file name includes a path.abstract booleanCheck if it is a file or a directory.abstract booleanCheck if it is a regular file.abstract longGet the last modified date of a fileabstract voidRename a file if this is allowed.List the files and directories in the given directory.static OutputStreamnewFileChannelOutputStream(FileChannel channel, boolean append) Create a new output stream from the channel.Create an input stream to read from the file.newOutputStream(boolean append) Create an output stream to write into the file.abstract FileChannelOpen a random access file object.static voidRegister a file provider.abstract booleanDisable the ability to write.abstract longsize()Get the size of a file in bytesabstract FilePathNormalize a file name.toString()Get the string representation.static voidunregister(FilePath provider) Unregister a file provider.unwrap()Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).
-
Field Details
-
name
The complete path (which may be absolute or relative, depending on the file system).
-
-
Constructor Details
-
FilePath
public FilePath()
-
-
Method Details
-
get
Get the file path object for the given path. Windows-style '\' is replaced with '/'.- Parameters:
path- the path- Returns:
- the file path object
-
register
Register a file provider.- Parameters:
provider- the file provider
-
unregister
Unregister a file provider.- Parameters:
provider- the file provider
-
size
public abstract long size()Get the size of a file in bytes- Returns:
- the size in bytes
-
moveTo
Rename a file if this is allowed.- Parameters:
newName- the new fully qualified file nameatomicReplace- whether the move should be atomic, and the target file should be replaced if it exists and replacing is possible
-
createFile
public abstract boolean createFile()Create a new file.- Returns:
- true if creating was successful
-
exists
public abstract boolean exists()Checks if a file exists.- Returns:
- true if it exists
-
delete
public abstract void delete()Delete a file or directory if it exists. Directories may only be deleted if they are empty. -
newDirectoryStream
List the files and directories in the given directory.- Returns:
- the list of fully qualified file names
-
toRealPath
Normalize a file name.- Returns:
- the normalized file name
-
getParent
Get the parent directory of a file or directory.- Returns:
- the parent directory name
-
isDirectory
public abstract boolean isDirectory()Check if it is a file or a directory.- Returns:
- true if it is a directory
-
isRegularFile
public abstract boolean isRegularFile()Check if it is a regular file.- Returns:
- true if it is a regular file
-
isAbsolute
public abstract boolean isAbsolute()Check if the file name includes a path.- Returns:
- if the file name is absolute
-
lastModified
public abstract long lastModified()Get the last modified date of a file- Returns:
- the last modified date
-
canWrite
public abstract boolean canWrite()Check if the file is writable.- Returns:
- if the file is writable
-
createDirectory
public abstract void createDirectory()Create a directory (all required parent directories already exist). -
getName
Get the file or directory name (the last element of the path).- Returns:
- the last element of the path
-
newOutputStream
Create an output stream to write into the file.- Parameters:
append- if true, the file will grow, if false, the file will be truncated first- Returns:
- the output stream
- Throws:
IOException- If an I/O error occurs
-
newFileChannelOutputStream
public static OutputStream newFileChannelOutputStream(FileChannel channel, boolean append) throws IOException Create a new output stream from the channel.- Parameters:
channel- the file channelappend- true for append mode, false for truncate and overwrite- Returns:
- the output stream
- Throws:
IOException- on I/O exception
-
open
Open a random access file object.- Parameters:
mode- the access mode. Supported are r, rw, rws, rwd- Returns:
- the file object
- Throws:
IOException- If an I/O error occurs
-
newInputStream
Create an input stream to read from the file.- Returns:
- the input stream
- Throws:
IOException- If an I/O error occurs
-
setReadOnly
public abstract boolean setReadOnly()Disable the ability to write.- Returns:
- true if the call was successful
-
createTempFile
Create a new temporary file.- Parameters:
suffix- the suffixinTempDir- if the file should be stored in the temporary directory- Returns:
- the name of the created file
- Throws:
IOException- on failure
-
toString
Get the string representation. The returned string can be used to construct a new object. -
getScheme
Get the scheme (prefix) for this file provider. This is similar tojava.nio.file.spi.FileSystemProvider.getScheme.- Returns:
- the scheme
-
getPath
Convert a file to a path. This is similar tojava.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- the path- Returns:
- the file path object
-
unwrap
Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).- Returns:
- the unwrapped path
-