Package org.apache.cassandra.io.util
Class FileUtils
- java.lang.Object
-
- org.apache.cassandra.io.util.FileUtils
-
public final class FileUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidappend(File file, java.lang.String... lines)static voidappendAndSync(File file, java.lang.String... lines)static voidclean(java.nio.ByteBuffer buffer)static voidclose(java.io.Closeable... cs)static voidclose(java.lang.Iterable<? extends java.io.Closeable> cs)static voidcloseQuietly(java.io.Closeable c)static voidcloseQuietly(java.lang.AutoCloseable c)static voidcloseQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs)static voidcopyWithConfirm(java.lang.String from, java.lang.String to)static voidcopyWithConfirm(File from, File to)static voidcopyWithOutConfirm(java.lang.String from, java.lang.String to)static FilecreateDeletableTempFile(java.lang.String prefix, java.lang.String suffix)static voidcreateDirectory(java.lang.String directory)Deprecated.static voidcreateDirectory(File directory)Deprecated.static voidcreateHardLink(java.lang.String from, java.lang.String to)static voidcreateHardLink(File from, File to)static voidcreateHardLinkWithConfirm(java.lang.String from, java.lang.String to)static voidcreateHardLinkWithConfirm(File from, File to)static voidcreateHardLinkWithoutConfirm(java.lang.String from, java.lang.String to)static FilecreateTempFile(java.lang.String prefix, java.lang.String suffix)static FilecreateTempFile(java.lang.String prefix, java.lang.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 booleandelete(java.lang.String file)Deprecated.static voiddelete(File... files)Deprecated.static voiddeleteDirectoryIfEmpty(java.nio.file.Path path)Deletes the specified directory if it is emptystatic voiddeleteRecursive(File dir)Deprecated.static voiddeleteRecursiveOnExit(File dir)Deprecated.static voiddeleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter)Deprecated.static voiddeleteWithConfirm(java.lang.String file)Deprecated.static voiddeleteWithConfirm(File file)Deprecated.static java.lang.ThrowabledeleteWithConfirm(File file, java.lang.Throwable accumulate)Deprecated.static java.lang.ThrowabledeleteWithConfirm(File file, java.lang.Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter)Deprecated.static longfolderSize(File folder)Get the size of a directory in bytesstatic java.lang.StringgetCanonicalPath(java.lang.String filename)static java.lang.StringgetCanonicalPath(File file)static FilegetTempDir()static voidhandleCorruptSSTable(CorruptSSTableException e)static voidhandleFSError(FSError e)static voidhandleFSErrorAndPropagate(FSError e)handleFSErrorAndPropagate will invoke the disk failure policy error handler, which may or may not stop the daemon or transports.static voidhandleStartupFSError(java.lang.Throwable t)static booleanisContained(File folder, File file)Return true if file is contained in folderstatic booleanisSubDirectory(File parent, File child)Deprecated.static voidmoveRecursively(java.nio.file.Path source, java.nio.file.Path target)Moves the contents of a directory to another directory.static longparseFileSize(java.lang.String value)static java.util.List<java.lang.String>readLines(File file)static voidrenameWithConfirm(java.lang.String from, java.lang.String to)Deprecated.static voidrenameWithConfirm(File from, File to)Deprecated.static voidrenameWithOutConfirm(java.lang.String from, java.lang.String to)Deprecated.static voidreplace(File file, java.lang.String... lines)static voidsetFSErrorHandler(FSErrorHandler handler)static java.lang.StringstringifyFileSize(double value)static voidtruncate(java.lang.String path, long size)static voidwrite(File file, java.util.List<java.lang.String> lines, java.nio.file.StandardOpenOption... options)Write lines to a file adding a newline to the end of each supplied line using the provided open options.
-
-
-
Field Detail
-
CHARSET
public static final java.nio.charset.Charset CHARSET
-
ONE_KIB
public static final long ONE_KIB
- See Also:
- Constant Field Values
-
ONE_MIB
public static final long ONE_MIB
- See Also:
- Constant Field Values
-
ONE_GIB
public static final long ONE_GIB
- See Also:
- Constant Field Values
-
ONE_TIB
public static final long ONE_TIB
- See Also:
- Constant Field Values
-
-
Method Detail
-
getTempDir
public static File getTempDir()
-
createTempFile
public static File createTempFile(java.lang.String prefix, java.lang.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.
-
createTempFile
public static File createTempFile(java.lang.String prefix, java.lang.String suffix)
-
createDeletableTempFile
public static File createDeletableTempFile(java.lang.String prefix, java.lang.String suffix)
-
createHardLink
public static void createHardLink(java.lang.String from, java.lang.String to)
-
createHardLinkWithConfirm
public static void createHardLinkWithConfirm(java.lang.String from, java.lang.String to)
-
createHardLinkWithoutConfirm
public static void createHardLinkWithoutConfirm(java.lang.String from, java.lang.String to)
-
copyWithOutConfirm
public static void copyWithOutConfirm(java.lang.String from, java.lang.String to)
-
copyWithConfirm
public static void copyWithConfirm(java.lang.String from, java.lang.String to)
-
truncate
public static void truncate(java.lang.String path, long size)
-
closeQuietly
public static void closeQuietly(java.io.Closeable c)
-
closeQuietly
public static void closeQuietly(java.lang.AutoCloseable c)
-
close
public static void close(java.io.Closeable... cs) throws java.io.IOException- Throws:
java.io.IOException
-
close
public static void close(java.lang.Iterable<? extends java.io.Closeable> cs) throws java.io.IOException- Throws:
java.io.IOException
-
closeQuietly
public static void closeQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs)
-
getCanonicalPath
public static java.lang.String getCanonicalPath(java.lang.String filename)
-
getCanonicalPath
public static java.lang.String getCanonicalPath(File file)
-
isContained
public static boolean isContained(File folder, File file)
Return true if file is contained in folder
-
clean
public static void clean(java.nio.ByteBuffer buffer)
-
parseFileSize
public static long parseFileSize(java.lang.String value)
-
stringifyFileSize
public static java.lang.String stringifyFileSize(double value)
-
handleCorruptSSTable
public static void handleCorruptSSTable(CorruptSSTableException e)
-
handleFSError
public static void handleFSError(FSError e)
-
handleStartupFSError
public static void handleStartupFSError(java.lang.Throwable t)
-
handleFSErrorAndPropagate
public static void handleFSErrorAndPropagate(FSError e)
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
public static long folderSize(File folder)
Get the size of a directory in bytes- Parameters:
folder- The directory for which we need size.- Returns:
- The size of the directory
-
append
public static void append(File file, java.lang.String... lines)
-
appendAndSync
public static void appendAndSync(File file, java.lang.String... lines)
-
replace
public static void replace(File file, java.lang.String... lines)
-
write
public static void write(File file, java.util.List<java.lang.String> lines, java.nio.file.StandardOpenOption... options)
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
public static java.util.List<java.lang.String> readLines(File file)
-
setFSErrorHandler
public static void setFSErrorHandler(FSErrorHandler handler)
-
createDirectory
@Deprecated public static void createDirectory(java.lang.String directory)
Deprecated.
-
createDirectory
@Deprecated public static void createDirectory(File directory)
Deprecated.
-
delete
@Deprecated public static boolean delete(java.lang.String file)
Deprecated.
-
delete
@Deprecated public static void delete(File... files)
Deprecated.
-
deleteRecursiveWithThrottle
@Deprecated public static void deleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.Deletes 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 public static void deleteRecursive(File dir)
Deprecated.Deletes 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 public static void deleteRecursiveOnExit(File dir)
Deprecated.Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.- Parameters:
dir- Directory to be deleted
-
isSubDirectory
@Deprecated public static boolean isSubDirectory(File parent, File child)
Deprecated.
-
deleteWithConfirm
@Deprecated public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate)
Deprecated.
-
deleteWithConfirm
@Deprecated public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.
-
deleteWithConfirm
@Deprecated public static void deleteWithConfirm(java.lang.String file)
Deprecated.
-
deleteWithConfirm
@Deprecated public static void deleteWithConfirm(File file)
Deprecated.
-
renameWithOutConfirm
@Deprecated public static void renameWithOutConfirm(java.lang.String from, java.lang.String to)Deprecated.
-
renameWithConfirm
@Deprecated public static void renameWithConfirm(java.lang.String from, java.lang.String to)Deprecated.
-
moveRecursively
public static void moveRecursively(java.nio.file.Path source, java.nio.file.Path target) throws java.io.IOExceptionMoves 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:
java.io.IOException
-
deleteDirectoryIfEmpty
public static void deleteDirectoryIfEmpty(java.nio.file.Path path) throws java.io.IOExceptionDeletes the specified directory if it is empty- Parameters:
path- the path to the directory- Throws:
java.io.IOException
-
-