Class FileUtils

java.lang.Object
org.apache.cassandra.io.util.FileUtils

public final class FileUtils extends Object
  • Field Details

  • Method Details

    • getTempDir

      public static File getTempDir()
    • createTempFile

      public static File createTempFile(String prefix, String suffix, File directory)
      Pretty much like File.createTempFile(String, String, java.io.File), but with the guarantee that the "random" part of the generated file name between prefix and suffix is a positive, increasing long value.
    • createTempFile

      public static File createTempFile(String prefix, String suffix)
    • createDeletableTempFile

      public static File createDeletableTempFile(String prefix, String suffix)
    • createHardLink

      public static void createHardLink(String from, String to)
    • createHardLink

      public static void createHardLink(File from, File to)
    • createHardLinkWithConfirm

      public static void createHardLinkWithConfirm(String from, String to)
    • createHardLinkWithConfirm

      public static void createHardLinkWithConfirm(File from, File to)
    • createHardLinkWithoutConfirm

      public static void createHardLinkWithoutConfirm(String from, String to)
    • createHardLinkWithoutConfirm

      public static void createHardLinkWithoutConfirm(File from, File to)
    • copyWithOutConfirm

      public static void copyWithOutConfirm(String from, String to)
    • copyWithOutConfirm

      public static void copyWithOutConfirm(File from, File to)
    • copyWithConfirm

      public static void copyWithConfirm(String from, String to)
    • copyWithConfirm

      public static void copyWithConfirm(File from, File to)
    • truncate

      public static void truncate(String path, long size)
    • closeQuietly

      public static void closeQuietly(Closeable c)
    • closeQuietly

      public static void closeQuietly(AutoCloseable c)
    • close

      public static void close(Closeable... cs) throws IOException
      Throws:
      IOException
    • close

      public static void close(Iterable<? extends Closeable> cs) throws IOException
      Throws:
      IOException
    • closeQuietly

      public static void closeQuietly(Iterable<? extends AutoCloseable> cs)
    • getCanonicalPath

      public static String getCanonicalPath(String filename)
    • getCanonicalPath

      public static 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(ByteBuffer buffer)
    • parseFileSize

      public static long parseFileSize(String value)
    • stringifyFileSize

      public static String stringifyFileSize(double value)
    • handleCorruptSSTable

      public static void handleCorruptSSTable(CorruptSSTableException e)
    • handleFSError

      public static void handleFSError(FSError e)
    • handleStartupFSError

      public static void handleStartupFSError(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, String... lines)
    • appendAndSync

      public static void appendAndSync(File file, String... lines)
    • replace

      public static void replace(File file, String... lines)
    • write

      public static void write(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. 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 List<String> readLines(File file)
    • setFSErrorHandler

      public static void setFSErrorHandler(FSErrorHandler handler)
    • createDirectory

      @Deprecated(since="4.1") public static void createDirectory(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(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-16926
      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(since="4.1") public static void deleteRecursive(File dir)
      Deprecated.
      See CASSANDRA-16926
      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(since="4.1") public static void deleteRecursiveOnExit(File dir)
      Deprecated.
      See CASSANDRA-16926
      Schedules 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 Throwable deleteWithConfirm(File file, Throwable accumulate)
      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(since="4.1") public static void deleteWithConfirm(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(String from, String to)
      Deprecated.
      See CASSANDRA-16926
    • renameWithConfirm

      @Deprecated(since="4.1") public static void renameWithConfirm(String from, 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(Path source, Path target) throws 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 move
      target - the directory where the files must be moved
      Throws:
      IOException
    • deleteDirectoryIfEmpty

      public static void deleteDirectoryIfEmpty(Path path) throws IOException
      Deletes the specified directory if it is empty
      Parameters:
      path - the path to the directory
      Throws:
      IOException
    • getBlockSize

      public static int getBlockSize(File directory)