Package org.apache.cassandra.io.util
Class FileUtils
java.lang.Object
org.apache.cassandra.io.util.FileUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidappendAndSync(File file, String... lines) static voidclean(ByteBuffer buffer) static voidstatic voidstatic voidstatic voidstatic voidcloseQuietly(Iterable<? extends AutoCloseable> cs) static voidcopyWithConfirm(String from, String to) static voidcopyWithConfirm(File from, File to) static voidcopyWithOutConfirm(String from, String to) static voidcopyWithOutConfirm(File from, File to) static FilecreateDeletableTempFile(String prefix, String suffix) static voidcreateDirectory(String directory) Deprecated.See CASSANDRA-16926static voidcreateDirectory(File directory) Deprecated.See CASSANDRA-16926static voidcreateHardLink(String from, String to) static voidcreateHardLink(File from, File to) static voidcreateHardLinkWithConfirm(String from, String to) static voidcreateHardLinkWithConfirm(File from, File to) static voidcreateHardLinkWithoutConfirm(String from, String to) static voidcreateHardLinkWithoutConfirm(File from, File to) static FilecreateTempFile(String prefix, String suffix) static FilecreateTempFile(String prefix, String suffix, File directory) Pretty much likeFile.createTempFile(String, String, java.io.File), but with the guarantee that the "random" part of the generated file name betweenprefixandsuffixis a positive, increasinglongvalue.static booleanDeprecated.See CASSANDRA-16926static voidDeprecated.See CASSANDRA-16926static voiddeleteDirectoryIfEmpty(Path path) Deletes the specified directory if it is emptystatic voiddeleteRecursive(File dir) Deprecated.See CASSANDRA-16926static voidDeprecated.See CASSANDRA-16926static voiddeleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter) Deprecated.See CASSANDRA-16926static voiddeleteWithConfirm(String file) Deprecated.See CASSANDRA-16926static voiddeleteWithConfirm(File file) Deprecated.See CASSANDRA-16926static ThrowabledeleteWithConfirm(File file, Throwable accumulate) Deprecated.See CASSANDRA-16926static ThrowabledeleteWithConfirm(File file, Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter) Deprecated.See CASSANDRA-16926static longfolderSize(File folder) Get the size of a directory in bytesstatic intgetBlockSize(File directory) static StringgetCanonicalPath(String filename) static StringgetCanonicalPath(File file) static Filestatic voidstatic voidstatic voidhandleFSErrorAndPropagate will invoke the disk failure policy error handler, which may or may not stop the daemon or transports.static voidstatic booleanisContained(File folder, File file) Return true if file is contained in folderstatic booleanisSubDirectory(File parent, File child) Deprecated.See CASSANDRA-16926static voidmoveRecursively(Path source, Path target) Moves the contents of a directory to another directory.static longparseFileSize(String value) static voidrenameWithConfirm(String from, String to) Deprecated.See CASSANDRA-16926static voidrenameWithConfirm(File from, File to) Deprecated.See CASSANDRA-16926static voidrenameWithOutConfirm(String from, String to) Deprecated.See CASSANDRA-16926static voidstatic voidsetFSErrorHandler(FSErrorHandler handler) static StringstringifyFileSize(double value) static voidstatic voidwrite(File file, List<String> lines, StandardOpenOption... options) Write lines to a file adding a newline to the end of each supplied line using the provided open options.
-
Field Details
-
CHARSET
-
ONE_KIB
public static final long ONE_KIB- See Also:
-
ONE_MIB
public static final long ONE_MIB- See Also:
-
ONE_GIB
public static final long ONE_GIB- See Also:
-
ONE_TIB
public static final long ONE_TIB- See Also:
-
-
Method Details
-
getTempDir
-
createTempFile
Pretty much likeFile.createTempFile(String, String, java.io.File), but with the guarantee that the "random" part of the generated file name betweenprefixandsuffixis a positive, increasinglongvalue. -
createTempFile
-
createDeletableTempFile
-
createHardLink
-
createHardLink
-
createHardLinkWithConfirm
-
createHardLinkWithConfirm
-
createHardLinkWithoutConfirm
-
createHardLinkWithoutConfirm
-
copyWithOutConfirm
-
copyWithOutConfirm
-
copyWithConfirm
-
copyWithConfirm
-
truncate
-
closeQuietly
-
closeQuietly
-
close
- Throws:
IOException
-
close
- Throws:
IOException
-
closeQuietly
-
getCanonicalPath
-
getCanonicalPath
-
isContained
Return true if file is contained in folder -
clean
-
parseFileSize
-
stringifyFileSize
-
handleCorruptSSTable
-
handleFSError
-
handleStartupFSError
-
handleFSErrorAndPropagate
handleFSErrorAndPropagate will invoke the disk failure policy error handler, which may or may not stop the daemon or transports. However, if we don't exit, we still want to propagate the exception to the caller in case they have custom exception handling- Parameters:
e- A filesystem error
-
folderSize
Get the size of a directory in bytes- Parameters:
folder- The directory for which we need size.- Returns:
- The size of the directory
-
append
-
appendAndSync
-
replace
-
write
Write lines to a file adding a newline to the end of each supplied line using the provided open options. If open option sync or dsync is provided this will not open the file with sync or dsync since it might end up syncing many times for a lot of lines. Instead it will write all the lines and sync once at the end. Since the file is never returned there is not much difference from the perspective of the caller.- Parameters:
file-lines-options-
-
readLines
-
setFSErrorHandler
-
createDirectory
Deprecated.See CASSANDRA-16926 -
createDirectory
Deprecated.See CASSANDRA-16926 -
delete
Deprecated.See CASSANDRA-16926 -
delete
Deprecated.See CASSANDRA-16926 -
deleteRecursiveWithThrottle
@Deprecated(since="4.1") public static void deleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter) Deprecated.See CASSANDRA-16926Deletes all files and subdirectories under "dir".- Parameters:
dir- Directory to be deleted- Throws:
FSWriteError- if any part of the tree cannot be deleted
-
deleteRecursive
Deprecated.See CASSANDRA-16926Deletes all files and subdirectories under "dir".- Parameters:
dir- Directory to be deleted- Throws:
FSWriteError- if any part of the tree cannot be deleted
-
deleteRecursiveOnExit
Deprecated.See CASSANDRA-16926Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.- Parameters:
dir- Directory to be deleted
-
isSubDirectory
Deprecated.See CASSANDRA-16926 -
deleteWithConfirm
Deprecated.See CASSANDRA-16926 -
deleteWithConfirm
@Deprecated(since="4.1") public static Throwable deleteWithConfirm(File file, Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter) Deprecated.See CASSANDRA-16926 -
deleteWithConfirm
Deprecated.See CASSANDRA-16926 -
deleteWithConfirm
Deprecated.See CASSANDRA-16926 -
renameWithOutConfirm
Deprecated.See CASSANDRA-16926 -
renameWithConfirm
Deprecated.See CASSANDRA-16926 -
renameWithConfirm
Deprecated.See CASSANDRA-16926 -
moveRecursively
Moves the contents of a directory to another directory.Once a file has been copied to the target directory it will be deleted from the source directory. If a file already exists in the target directory a warning will be logged and the file will not be deleted.
- Parameters:
source- the directory containing the files to movetarget- the directory where the files must be moved- Throws:
IOException
-
deleteDirectoryIfEmpty
Deletes the specified directory if it is empty- Parameters:
path- the path to the directory- Throws:
IOException
-
getBlockSize
-