Package org.apache.cassandra.io.util
Class File
java.lang.Object
org.apache.cassandra.io.util.File
- All Implemented Interfaces:
Comparable<File>
A thin wrapper around java.nio.file.Path to provide more ergonomic functionality.
TODO codebase probably should not use tryList, as unexpected exceptions are hidden;
probably want to introduce e.g. listIfExists
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate a File equivalent to the java.io.File providedConstruct a File representing the childchildofparentConstruct a File representing the providedpathConstruct a File representing the childchildofparentConvenience constructor equivalent tonew File(Paths.get(path))File(FileSystem fs, String first, String... more) Unsafe constructor that allows a File to use a differetFileSystemthanfilesystem.Construct a File representing the childchildofparentConstruct a File representing the childchildofparent -
Method Summary
Modifier and TypeMethodDescriptionintbooleanbooleanTry to create a new regular file at this path.voiddelete()This file will be deleted, with any failures being reported with an FSErrorvoiddelete(com.google.common.util.concurrent.RateLimiter rateLimiter) This file will be deleted, obeying the provided rate limiter.This file will be deleted, and any exceptions encountered merged withaccumulateto the return valueThis file will be deleted, obeying the provided rate limiter.voidThis file will be deleted, with any failures being reported with an FSErrorvoidTry to delete the file on process exit.voidDeletes all files and subdirectories under "dir".voiddeleteRecursive(com.google.common.util.concurrent.RateLimiter rateLimiter) Deletes all files and subdirectories under "dir".voidThis file will be deleted on clean shutdown; if it is a directory, its entire contents at the time of shutdown will be deletedbooleanbooleanexists()voidvoidforEachRecursive(Consumer<File> forEach) static PathinthashCode()booleanbooleanisAncestorOf(File child) booleanbooleanbooleanisFile()booleanbooleanlonglonglength()File[]list()File[]list(BiPredicate<File, String> filter) File[]String[]String[]listNames(BiPredicate<File, String> filter) String[]String[]listNamesUnchecked(BiPredicate<File, String> filter) File[]File[]listUnchecked(BiPredicate<File, String> filter) File[]listUnchecked(Predicate<File> filter) voidAtomically (if supported) rename/move this file totoname()newWriter(File.WriteMode mode) parent()path()static StringtoPath()toString()booleanTry to create a directory at this path, creating any parent directories as necessary.booleanTry to create a directory at this path.booleanTry to delete the file, returning true iff it was deleted by us.File[]tryList()File[]tryList(BiPredicate<File, String> filter) File[]String[]String[]tryListNames(BiPredicate<File, String> filter) tryListNames(BiPredicate<File, String> filter, net.openhft.chronicle.core.util.ThrowingFunction<IOException, String[], T> orElse) tryListNames(net.openhft.chronicle.core.util.ThrowingFunction<IOException, String[], T> orElse) booleanTry to rename the file atomically, if the system supports it.booleantrySetExecutable(boolean value) Try to set if the path is executable by its ownerbooleantrySetLastModified(long value) Try to set the last modified time in millis of the pathbooleantrySetReadable(boolean value) Try to set if the path is readable by its ownerbooleantrySetWritable(boolean value) Try to set if the path is writable by its ownerstatic FileSystemstatic voidwithSuffix(String suffix)
-
Constructor Details
-
File
Construct a File representing the childchildofparent -
File
Construct a File representing the childchildofparent -
File
Construct a File representing the childchildofparent -
File
Construct a File representing the providedpath -
File
Create a File equivalent to the java.io.File provided -
File
Construct a File representing the childchildofparent -
File
Convenience constructor equivalent tonew File(Paths.get(path)) -
File
Unsafe constructor that allows a File to use a differetFileSystemthanfilesystem. The main caller of such a method are cases such as JVM Dtest functions that need access to the logging framwork files, which exists on inFileSystems.getDefault(). -
File
- Parameters:
path- the path to wrap
-
-
Method Details
-
pathSeparator
-
getPath
-
tryDelete
public boolean tryDelete()Try to delete the file, returning true iff it was deleted by us. Does not ordinarily throw exceptions. -
delete
This file will be deleted, and any exceptions encountered merged withaccumulateto the return value -
delete
public Throwable delete(Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter) This file will be deleted, obeying the provided rate limiter. Any exceptions encountered will be merged withaccumulateto the return value -
delete
public void delete()This file will be deleted, with any failures being reported with an FSError- Throws:
FSWriteError- if cannot be deleted
-
deleteIfExists
public void deleteIfExists()This file will be deleted, with any failures being reported with an FSError- Throws:
FSWriteError- if cannot be deleted
-
delete
public void delete(com.google.common.util.concurrent.RateLimiter rateLimiter) This file will be deleted, obeying the provided rate limiter.- Throws:
FSWriteError- if cannot be deleted
-
deleteRecursive
public void deleteRecursive(com.google.common.util.concurrent.RateLimiter rateLimiter) Deletes all files and subdirectories under "dir".- Throws:
FSWriteError- if any part of the tree cannot be deleted
-
deleteRecursive
public void deleteRecursive()Deletes all files and subdirectories under "dir".- Throws:
FSWriteError- if any part of the tree cannot be deleted
-
deleteOnExit
public void deleteOnExit()Try to delete the file on process exit. -
deleteRecursiveOnExit
public void deleteRecursiveOnExit()This file will be deleted on clean shutdown; if it is a directory, its entire contents at the time of shutdown will be deleted -
tryMove
Try to rename the file atomically, if the system supports it.- Returns:
- true iff successful, false if it fails for any reason.
-
move
Atomically (if supported) rename/move this file toto- Throws:
FSWriteError- if any part of the tree cannot be deleted
-
length
public long length()- Returns:
- the length of the file if it exists and if we can read it; 0 otherwise.
-
lastModified
public long lastModified()- Returns:
- the last modified time in millis of the path if it exists and we can read it; 0 otherwise.
-
trySetLastModified
public boolean trySetLastModified(long value) Try to set the last modified time in millis of the path- Returns:
- true if it exists and we can write it; return false otherwise.
-
trySetReadable
public boolean trySetReadable(boolean value) Try to set if the path is readable by its owner- Returns:
- true if it exists and we can write it; return false otherwise.
-
trySetWritable
public boolean trySetWritable(boolean value) Try to set if the path is writable by its owner- Returns:
- true if it exists and we can write it; return false otherwise.
-
trySetExecutable
public boolean trySetExecutable(boolean value) Try to set if the path is executable by its owner- Returns:
- true if it exists and we can write it; return false otherwise.
-
exists
public boolean exists()- Returns:
- true if the path exists, false if it does not, or we cannot determine due to some exception
-
isDirectory
public boolean isDirectory()- Returns:
- true if the path refers to a directory
-
isFile
public boolean isFile()- Returns:
- true if the path refers to a regular file
-
isReadable
public boolean isReadable()- Returns:
- true if the path can be read by us
-
isWritable
public boolean isWritable()- Returns:
- true if the path can be written by us
-
isExecutable
public boolean isExecutable()- Returns:
- true if the path can be executed by us
-
createFileIfNotExists
public boolean createFileIfNotExists()Try to create a new regular file at this path.- Returns:
- true if successful, false if it already exists
-
createDirectoriesIfNotExists
public boolean createDirectoriesIfNotExists() -
tryCreateDirectory
public boolean tryCreateDirectory()Try to create a directory at this path. Return true if a new directory was created at this path, and false otherwise. -
tryCreateDirectories
public boolean tryCreateDirectories()Try to create a directory at this path, creating any parent directories as necessary.- Returns:
- true if a new directory was created at this path, and false otherwise.
-
parent
- Returns:
- the parent file, or null if none
-
parentPath
- Returns:
- the parent file's path, or null if none
-
isAbsolute
public boolean isAbsolute()- Returns:
- true if the path has no relative path elements
-
isAncestorOf
-
toAbsolute
- Returns:
- a File that represents the same path as this File with any relative path elements resolved. If this is the empty File, returns the working directory.
-
absolutePath
-
toCanonical
- Returns:
- a File that represents the same path as this File with any relative path elements and links resolved. If this is the empty File, returns the working directory.
-
canonicalPath
-
name
- Returns:
- the last path element for this file
-
forEach
-
forEachRecursive
-
tryListNames
- Returns:
- if a directory, the names of the files within; null otherwise
-
tryListNames
- Returns:
- if a directory, the names of the files within, filtered by the provided predicate; null otherwise
-
tryList
- Returns:
- if a directory, the files within; null otherwise
-
tryList
- Returns:
- if a directory, the files within, filtered by the provided predicate; null otherwise
-
tryList
- Returns:
- if a directory, the files within, filtered by the provided predicate; null otherwise
-
listNames
- Returns:
- if a directory, the names of the files within; null otherwise
- Throws:
IOException
-
listNames
- Returns:
- if a directory, the names of the files within, filtered by the provided predicate; null otherwise
- Throws:
IOException
-
list
- Returns:
- if a directory, the files within; null otherwise
- Throws:
IOException
-
list
- Returns:
- if a directory, the files within, filtered by the provided predicate; null otherwise
- Throws:
IOException
-
list
- Returns:
- if a directory, the files within, filtered by the provided predicate; null otherwise
- Throws:
IOException
-
listNamesUnchecked
- Returns:
- if a directory, the names of the files within; null otherwise
- Throws:
UncheckedIOException
-
listNamesUnchecked
- Returns:
- if a directory, the names of the files within, filtered by the provided predicate; null otherwise
- Throws:
UncheckedIOException
-
listUnchecked
- Returns:
- if a directory, the files within; null otherwise
- Throws:
UncheckedIOException
-
listUnchecked
- Returns:
- if a directory, the files within, filtered by the provided predicate; null otherwise
- Throws:
UncheckedIOException
-
listUnchecked
- Returns:
- if a directory, the files within, filtered by the provided predicate; throw an UncheckedIO exception otherwise
- Throws:
UncheckedIOException
-
tryListNames
public <T extends Throwable> String[] tryListNames(net.openhft.chronicle.core.util.ThrowingFunction<IOException, String[], throws TT> orElse) - Returns:
- if a directory, the names of the files within; null otherwise
- Throws:
T extends Throwable
-
tryListNames
public <T extends Throwable> String[] tryListNames(BiPredicate<File, String> filter, net.openhft.chronicle.core.util.ThrowingFunction<IOException, throws TString[], T> orElse) - Returns:
- if a directory, the names of the files within, filtered by the provided predicate; null otherwise
- Throws:
T extends Throwable
-
path
- Returns:
- the path of this file
-
toPath
- Returns:
- the
Pathof this file
-
toString
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<File>
-
toJavaIOFile
-
newReadChannel
- Returns:
- a new
FileChannelfor reading - Throws:
NoSuchFileException
-
newReadWriteChannel
- Returns:
- a new
FileChannelfor reading or writing; file will be created if it doesn't exist - Throws:
NoSuchFileException
-
newWriteChannel
- Parameters:
mode- whether or not the channel appends to the underlying file- Returns:
- a new
FileChannelfor writing; file will be created if it doesn't exist - Throws:
NoSuchFileException
-
newWriter
- Throws:
IOException
-
newOutputStream
- Throws:
NoSuchFileException
-
newInputStream
- Throws:
NoSuchFileException
-
withSuffix
-
unsafeGetFilesystem
-
unsafeSetFilesystem
-