Package org.h2.store.fs
Class FilePathWrapper
- java.lang.Object
-
- org.h2.store.fs.FilePath
-
- org.h2.store.fs.FilePathWrapper
-
- Direct Known Subclasses:
FilePathAsync,FilePathCache,FilePathEncrypt,FilePathNioMapped,FilePathRec,FilePathRetryOnInterrupt,FilePathSplit
public abstract class FilePathWrapper extends FilePath
The base class for wrapping / delegating file systems such as the split file system.
-
-
Constructor Summary
Constructors Constructor Description FilePathWrapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanWrite()Check if the file is writable.private FilePathWrappercreate(java.lang.String path, FilePath base)voidcreateDirectory()Create a directory (all required parent directories already exist).booleancreateFile()Create a new file.FilePathcreateTempFile(java.lang.String suffix, boolean inTempDir)Create a new temporary file.voiddelete()Delete a file or directory if it exists.booleanexists()Checks if a file exists.protected FilePathgetBase()FilePathgetParent()Get the parent directory of a file or directory.FilePathWrappergetPath(java.lang.String path)Convert a file to a path.protected java.lang.StringgetPrefix()booleanisAbsolute()Check if the file name includes a path.booleanisDirectory()Check if it is a file or a directory.longlastModified()Get the last modified date of a filevoidmoveTo(FilePath newName, boolean atomicReplace)Rename a file if this is allowed.java.util.List<FilePath>newDirectoryStream()List the files and directories in the given directory.java.io.InputStreamnewInputStream()Create an input stream to read from the file.java.io.OutputStreamnewOutputStream(boolean append)Create an output stream to write into the file.java.nio.channels.FileChannelopen(java.lang.String mode)Open a random access file object.booleansetReadOnly()Disable the ability to write.longsize()Get the size of a file in bytesFilePathtoRealPath()Normalize a file name.FilePathunwrap()Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).protected FilePathunwrap(java.lang.String path)Get the base path for the given wrapped path.FilePathWrapperwrap(FilePath base)Create a wrapped path instance for the given base path.-
Methods inherited from class org.h2.store.fs.FilePath
get, getName, getScheme, newFileChannelOutputStream, register, toString, unregister
-
-
-
-
Field Detail
-
base
private FilePath base
-
-
Method Detail
-
getPath
public FilePathWrapper getPath(java.lang.String path)
Description copied from class:FilePathConvert 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.
-
wrap
public FilePathWrapper wrap(FilePath base)
Create a wrapped path instance for the given base path.- Parameters:
base- the base path- Returns:
- the wrapped path
-
unwrap
public FilePath unwrap()
Description copied from class:FilePathGet the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).
-
create
private FilePathWrapper create(java.lang.String path, FilePath base)
-
getPrefix
protected java.lang.String getPrefix()
-
unwrap
protected FilePath unwrap(java.lang.String path)
Get the base path for the given wrapped path.- Parameters:
path- the path including the scheme prefix- Returns:
- the base file path
-
getBase
protected FilePath getBase()
-
canWrite
public boolean canWrite()
Description copied from class:FilePathCheck if the file is writable.
-
createDirectory
public void createDirectory()
Description copied from class:FilePathCreate a directory (all required parent directories already exist).- Specified by:
createDirectoryin classFilePath
-
createFile
public boolean createFile()
Description copied from class:FilePathCreate a new file.- Specified by:
createFilein classFilePath- Returns:
- true if creating was successful
-
delete
public void delete()
Description copied from class:FilePathDelete a file or directory if it exists. Directories may only be deleted if they are empty.
-
exists
public boolean exists()
Description copied from class:FilePathChecks if a file exists.
-
getParent
public FilePath getParent()
Description copied from class:FilePathGet the parent directory of a file or directory.
-
isAbsolute
public boolean isAbsolute()
Description copied from class:FilePathCheck if the file name includes a path.- Specified by:
isAbsolutein classFilePath- Returns:
- if the file name is absolute
-
isDirectory
public boolean isDirectory()
Description copied from class:FilePathCheck if it is a file or a directory.- Specified by:
isDirectoryin classFilePath- Returns:
- true if it is a directory
-
lastModified
public long lastModified()
Description copied from class:FilePathGet the last modified date of a file- Specified by:
lastModifiedin classFilePath- Returns:
- the last modified date
-
toRealPath
public FilePath toRealPath()
Description copied from class:FilePathNormalize a file name.- Specified by:
toRealPathin classFilePath- Returns:
- the normalized file name
-
newDirectoryStream
public java.util.List<FilePath> newDirectoryStream()
Description copied from class:FilePathList the files and directories in the given directory.- Specified by:
newDirectoryStreamin classFilePath- Returns:
- the list of fully qualified file names
-
moveTo
public void moveTo(FilePath newName, boolean atomicReplace)
Description copied from class:FilePathRename a file if this is allowed.
-
newInputStream
public java.io.InputStream newInputStream() throws java.io.IOExceptionDescription copied from class:FilePathCreate an input stream to read from the file.- Overrides:
newInputStreamin classFilePath- Returns:
- the input stream
- Throws:
java.io.IOException- If an I/O error occurs
-
newOutputStream
public java.io.OutputStream newOutputStream(boolean append) throws java.io.IOExceptionDescription copied from class:FilePathCreate an output stream to write into the file.- Overrides:
newOutputStreamin classFilePath- Parameters:
append- if true, the file will grow, if false, the file will be truncated first- Returns:
- the output stream
- Throws:
java.io.IOException- If an I/O error occurs
-
open
public java.nio.channels.FileChannel open(java.lang.String mode) throws java.io.IOExceptionDescription copied from class:FilePathOpen a random access file object.
-
setReadOnly
public boolean setReadOnly()
Description copied from class:FilePathDisable the ability to write.- Specified by:
setReadOnlyin classFilePath- Returns:
- true if the call was successful
-
size
public long size()
Description copied from class:FilePathGet the size of a file in bytes
-
createTempFile
public FilePath createTempFile(java.lang.String suffix, boolean inTempDir) throws java.io.IOException
Description copied from class:FilePathCreate a new temporary file.- Overrides:
createTempFilein classFilePath- Parameters:
suffix- the suffixinTempDir- if the file should be stored in the temporary directory- Returns:
- the name of the created file
- Throws:
java.io.IOException- on failure
-
-