Package org.h2.store.fs.disk
Class FilePathDisk
- java.lang.Object
-
- org.h2.store.fs.FilePath
-
- org.h2.store.fs.disk.FilePathDisk
-
public class FilePathDisk extends FilePath
This file system stores files on disk. This is the most common file system.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CLASSPATH_PREFIX
-
Constructor Summary
Constructors Constructor Description FilePathDisk()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 inTempDir)
Create a new temporary file.void
delete()
Delete a file or directory if it exists.boolean
exists()
Checks if a file exists.static java.lang.String
expandUserHomeDirectory(java.lang.String fileName)
Expand '~' to the user home directory.(package private) static void
freeMemoryAndFinalize()
Call the garbage collection and run finalization.FilePath
getParent()
Get the parent directory of a file or directory.FilePathDisk
getPath(java.lang.String path)
Convert a file to a path.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 filevoid
moveTo(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.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.boolean
setReadOnly()
Disable the ability to write.long
size()
Get the size of a file in bytesFilePathDisk
toRealPath()
Normalize a file name.private static java.nio.file.Path
toRealPath(java.nio.file.Path path)
protected static java.lang.String
translateFileName(java.lang.String fileName)
Translate the file name to the native format.private static void
wait(int i)
-
Methods inherited from class org.h2.store.fs.FilePath
get, getName, newFileChannelOutputStream, register, toString, unregister, unwrap
-
-
-
-
Field Detail
-
CLASSPATH_PREFIX
private static final java.lang.String CLASSPATH_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPath
public FilePathDisk getPath(java.lang.String path)
Description copied from class:FilePath
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.
-
size
public long size()
Description copied from class:FilePath
Get the size of a file in bytes
-
translateFileName
protected static java.lang.String translateFileName(java.lang.String fileName)
Translate the file name to the native format. This will replace '\' with '/' and 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
-
moveTo
public void moveTo(FilePath newName, boolean atomicReplace)
Description copied from class:FilePath
Rename a file if this is allowed.
-
wait
private static void wait(int i)
-
createFile
public boolean createFile()
Description copied from class:FilePath
Create a new file.- Specified by:
createFile
in classFilePath
- Returns:
- true if creating was successful
-
exists
public boolean exists()
Description copied from class:FilePath
Checks if a file exists.
-
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.
-
newDirectoryStream
public java.util.List<FilePath> newDirectoryStream()
Description copied from class:FilePath
List the files and directories in the given directory.- Specified by:
newDirectoryStream
in classFilePath
- Returns:
- the list of fully qualified file names
-
canWrite
public boolean canWrite()
Description copied from class:FilePath
Check if the file is writable.
-
setReadOnly
public boolean setReadOnly()
Description copied from class:FilePath
Disable the ability to write.- Specified by:
setReadOnly
in classFilePath
- Returns:
- true if the call was successful
-
toRealPath
public FilePathDisk toRealPath()
Description copied from class:FilePath
Normalize a file name.- Specified by:
toRealPath
in classFilePath
- Returns:
- the normalized file name
-
toRealPath
private static java.nio.file.Path toRealPath(java.nio.file.Path path)
-
getParent
public FilePath getParent()
Description copied from class:FilePath
Get the parent directory of a file or directory.
-
isDirectory
public boolean isDirectory()
Description copied from class:FilePath
Check if it is a file or a directory.- Specified by:
isDirectory
in classFilePath
- Returns:
- true if it is a directory
-
isAbsolute
public boolean isAbsolute()
Description copied from class:FilePath
Check if the file name includes a path.- Specified by:
isAbsolute
in classFilePath
- Returns:
- if the file name is absolute
-
lastModified
public long lastModified()
Description copied from class:FilePath
Get the last modified date of a file- Specified by:
lastModified
in classFilePath
- Returns:
- the last modified date
-
createDirectory
public void createDirectory()
Description copied from class:FilePath
Create a directory (all required parent directories already exist).- Specified by:
createDirectory
in classFilePath
-
newOutputStream
public java.io.OutputStream newOutputStream(boolean append) throws java.io.IOException
Description copied from class:FilePath
Create an output stream to write into the file.- Overrides:
newOutputStream
in 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
-
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 classFilePath
- Returns:
- the input stream
- Throws:
java.io.IOException
- If an I/O error occurs
-
freeMemoryAndFinalize
static void freeMemoryAndFinalize()
Call the garbage collection and run finalization. This close all files that were not closed, and are no longer referenced.
-
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.
-
getScheme
public java.lang.String getScheme()
Description copied from class:FilePath
Get the scheme (prefix) for this file provider. This is similar tojava.nio.file.spi.FileSystemProvider.getScheme
.
-
createTempFile
public FilePath createTempFile(java.lang.String suffix, boolean inTempDir) throws java.io.IOException
Description copied from class:FilePath
Create a new temporary file.- Overrides:
createTempFile
in 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
-
-