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 void
append(File file, java.lang.String... lines)
static void
appendAndSync(File file, java.lang.String... lines)
static void
clean(java.nio.ByteBuffer buffer)
static void
close(java.io.Closeable... cs)
static void
close(java.lang.Iterable<? extends java.io.Closeable> cs)
static void
closeQuietly(java.io.Closeable c)
static void
closeQuietly(java.lang.AutoCloseable c)
static void
closeQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs)
static void
copyWithConfirm(java.lang.String from, java.lang.String to)
static void
copyWithConfirm(File from, File to)
static void
copyWithOutConfirm(java.lang.String from, java.lang.String to)
static void
copyWithOutConfirm(File from, File to)
static File
createDeletableTempFile(java.lang.String prefix, java.lang.String suffix)
static void
createDirectory(java.lang.String directory)
Deprecated.See CASSANDRA-16926static void
createDirectory(File directory)
Deprecated.See CASSANDRA-16926static void
createHardLink(java.lang.String from, java.lang.String to)
static void
createHardLink(File from, File to)
static void
createHardLinkWithConfirm(java.lang.String from, java.lang.String to)
static void
createHardLinkWithConfirm(File from, File to)
static void
createHardLinkWithoutConfirm(java.lang.String from, java.lang.String to)
static void
createHardLinkWithoutConfirm(File from, File to)
static File
createTempFile(java.lang.String prefix, java.lang.String suffix)
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 betweenprefix
andsuffix
is a positive, increasinglong
value.static boolean
delete(java.lang.String file)
Deprecated.See CASSANDRA-16926static void
delete(File... files)
Deprecated.See CASSANDRA-16926static void
deleteDirectoryIfEmpty(java.nio.file.Path path)
Deletes the specified directory if it is emptystatic void
deleteRecursive(File dir)
Deprecated.See CASSANDRA-16926static void
deleteRecursiveOnExit(File dir)
Deprecated.See CASSANDRA-16926static void
deleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.See CASSANDRA-16926static void
deleteWithConfirm(java.lang.String file)
Deprecated.See CASSANDRA-16926static void
deleteWithConfirm(File file)
Deprecated.See CASSANDRA-16926static java.lang.Throwable
deleteWithConfirm(File file, java.lang.Throwable accumulate)
Deprecated.See CASSANDRA-16926static java.lang.Throwable
deleteWithConfirm(File file, java.lang.Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.See CASSANDRA-16926static long
folderSize(File folder)
Get the size of a directory in bytesstatic int
getBlockSize(File directory)
static java.lang.String
getCanonicalPath(java.lang.String filename)
static java.lang.String
getCanonicalPath(File file)
static File
getTempDir()
static void
handleCorruptSSTable(CorruptSSTableException e)
static void
handleFSError(FSError e)
static void
handleFSErrorAndPropagate(FSError e)
handleFSErrorAndPropagate will invoke the disk failure policy error handler, which may or may not stop the daemon or transports.static void
handleStartupFSError(java.lang.Throwable t)
static boolean
isContained(File folder, File file)
Return true if file is contained in folderstatic boolean
isSubDirectory(File parent, File child)
Deprecated.See CASSANDRA-16926static void
moveRecursively(java.nio.file.Path source, java.nio.file.Path target)
Moves the contents of a directory to another directory.static long
parseFileSize(java.lang.String value)
static java.util.List<java.lang.String>
readLines(File file)
static void
renameWithConfirm(java.lang.String from, java.lang.String to)
Deprecated.See CASSANDRA-16926static void
renameWithConfirm(File from, File to)
Deprecated.See CASSANDRA-16926static void
renameWithOutConfirm(java.lang.String from, java.lang.String to)
Deprecated.See CASSANDRA-16926static void
replace(File file, java.lang.String... lines)
static void
setFSErrorHandler(FSErrorHandler handler)
static java.lang.String
stringifyFileSize(double value)
static void
truncate(java.lang.String path, long size)
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.
-
-
-
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 betweenprefix
andsuffix
is a positive, increasinglong
value.
-
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(since="4.1") public static void createDirectory(java.lang.String directory)
Deprecated.See CASSANDRA-16926
-
createDirectory
@Deprecated(since="4.1") public static void createDirectory(File directory)
Deprecated.See CASSANDRA-16926
-
delete
@Deprecated(since="4.1") public static boolean delete(java.lang.String file)
Deprecated.See CASSANDRA-16926
-
delete
@Deprecated(since="4.1") public static void delete(File... files)
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(since="4.1") public static void deleteRecursive(File dir)
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(since="4.1") public static void deleteRecursiveOnExit(File dir)
Deprecated.See CASSANDRA-16926Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.- Parameters:
dir
- Directory to be deleted
-
isSubDirectory
@Deprecated(since="4.1") public static boolean isSubDirectory(File parent, File child)
Deprecated.See CASSANDRA-16926
-
deleteWithConfirm
@Deprecated(since="4.1") public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate)
Deprecated.See CASSANDRA-16926
-
deleteWithConfirm
@Deprecated(since="4.1") public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.See CASSANDRA-16926
-
deleteWithConfirm
@Deprecated(since="4.1") public static void deleteWithConfirm(java.lang.String file)
Deprecated.See CASSANDRA-16926
-
deleteWithConfirm
@Deprecated(since="4.1") public static void deleteWithConfirm(File file)
Deprecated.See CASSANDRA-16926
-
renameWithOutConfirm
@Deprecated(since="4.1") public static void renameWithOutConfirm(java.lang.String from, java.lang.String to)
Deprecated.See CASSANDRA-16926
-
renameWithConfirm
@Deprecated(since="4.1") public static void renameWithConfirm(java.lang.String from, java.lang.String to)
Deprecated.See CASSANDRA-16926
-
renameWithConfirm
@Deprecated(since="4.1") public static void renameWithConfirm(File from, File to)
Deprecated.See CASSANDRA-16926
-
moveRecursively
public static void moveRecursively(java.nio.file.Path source, java.nio.file.Path target) throws java.io.IOException
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:
java.io.IOException
-
deleteDirectoryIfEmpty
public static void deleteDirectoryIfEmpty(java.nio.file.Path path) throws java.io.IOException
Deletes the specified directory if it is empty- Parameters:
path
- the path to the directory- Throws:
java.io.IOException
-
getBlockSize
public static int getBlockSize(File directory)
-
-