org.apache.cassandra.io.util

## Class FileUtils

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

-     public final class FileUtils
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.nio.charset.Charset` | `CHARSET`
    `static boolean` | `isCleanerAvailable`
    `static long` | `ONE_GB`
    `static long` | `ONE_KB`
    `static long` | `ONE_MB`
    `static long` | `ONE_TB`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `append(java.io.File file, java.lang.String... lines)`
    `static void` | `appendAndSync(java.io.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.lang.AutoCloseable c)`
    `static void` | `closeQuietly(java.io.Closeable c)`
    `static void` | `closeQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs)`
    `static void` | `copyTo(java.io.DataInput in, java.io.OutputStream out, int length)`
    `static void` | `createDirectory(java.io.File directory)`
    `static void` | `createDirectory(java.lang.String directory)`
    `static void` | `createHardLink(java.io.File from, java.io.File to)`
    `static void` | `createHardLink(java.lang.String from, java.lang.String to)`
    `static java.io.File` | `createTempFile(java.lang.String prefix, java.lang.String suffix)`
    `static java.io.File` | `createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)`
    `static void` | `delete(java.io.File... files)`
    `static boolean` | `delete(java.lang.String file)`
    `static void` | `deleteAsync(java.lang.String file)`
    `static void` | `deleteRecursive(java.io.File dir)` Deletes all files and subdirectories under "dir".
    `static void` | `deleteRecursiveOnExit(java.io.File dir)` Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.
    `static void` | `deleteWithConfirm(java.io.File file)`
    `static java.lang.Throwable` | `deleteWithConfirm(java.io.File file, boolean expect, java.lang.Throwable accumulate)`
    `static void` | `deleteWithConfirm(java.lang.String file)`
    `static java.lang.Throwable` | `deleteWithConfirm(java.lang.String filePath, boolean expect, java.lang.Throwable accumulate)`
    `static long` | `folderSize(java.io.File folder)` Get the size of a directory in bytes
    `static java.lang.String` | `getCanonicalPath(java.io.File file)`
    `static java.lang.String` | `getCanonicalPath(java.lang.String filename)`
    `static java.nio.file.FileStore` | `getFileStore(java.nio.file.Path path)` Returns the `FileStore` representing the file store where a file is located.
    `static long` | `getFreeSpace(java.io.File file)` Returns the number of unallocated bytes on the specified partition.
    `static java.lang.String` | `getRelativePath(java.lang.String basePath, java.lang.String path)` Convert absolute path into a path relative to the base path
    `static long` | `getTotalSpace(java.io.File file)` Returns the size of the specified partition.
    `static long` | `getUsableSpace(java.io.File file)` Returns the number of available bytes on the specified partition.
    `static void` | `handleCorruptSSTable(CorruptSSTableException e)`
    `static void` | `handleFSError(FSError e)`
    `static boolean` | `isContained(java.io.File folder, java.io.File file)` Return true if file is contained in folder
    `static boolean` | `isSubDirectory(java.io.File parent, java.io.File child)`
    `static java.util.List<java.lang.String>` | `readLines(java.io.File file)`
    `static void` | `renameWithConfirm(java.io.File from, java.io.File to)`
    `static void` | `renameWithConfirm(java.lang.String from, java.lang.String to)`
    `static void` | `renameWithOutConfirm(java.lang.String from, java.lang.String to)`
    `static void` | `replace(java.io.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` | `visitDirectory(java.nio.file.Path dir, java.util.function.Predicate<? super java.io.File> filter, java.util.function.Consumer<? super java.io.File> consumer)`
    `static void` | `write(java.io.File file, java.util.List<java.lang.String> lines, java.nio.file.StandardOpenOption... options)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CHARSET

          public static final java.nio.charset.Charset CHARSET

    - #### ONE_KB

          public static final long ONE_KB

      See Also:
        Constant Field Values

    - #### ONE_MB

          public static final long ONE_MB

      See Also:
        Constant Field Values

    - #### ONE_GB

          public static final long ONE_GB

      See Also:
        Constant Field Values

    - #### ONE_TB

          public static final long ONE_TB

      See Also:
        Constant Field Values

    - #### isCleanerAvailable

          public static final boolean isCleanerAvailable

  - ### Method Detail

    - #### createHardLink

          public static void createHardLink(java.lang.String from,
                                            java.lang.String to)

    - #### createHardLink

          public static void createHardLink(java.io.File from,
                                            java.io.File to)

    - #### createTempFile

          public static java.io.File createTempFile(java.lang.String prefix,
                                                    java.lang.String suffix,
                                                    java.io.File directory)

    - #### createTempFile

          public static java.io.File createTempFile(java.lang.String prefix,
                                                    java.lang.String suffix)

    - #### deleteWithConfirm

          public static java.lang.Throwable deleteWithConfirm(java.lang.String filePath,
                                                              boolean expect,
                                                              java.lang.Throwable accumulate)

    - #### deleteWithConfirm

          public static java.lang.Throwable deleteWithConfirm(java.io.File file,
                                                              boolean expect,
                                                              java.lang.Throwable accumulate)

    - #### deleteWithConfirm

          public static void deleteWithConfirm(java.lang.String file)

    - #### deleteWithConfirm

          public static void deleteWithConfirm(java.io.File file)

    - #### renameWithOutConfirm

          public static void renameWithOutConfirm(java.lang.String from,
                                                  java.lang.String to)

    - #### renameWithConfirm

          public static void renameWithConfirm(java.lang.String from,
                                               java.lang.String to)

    - #### renameWithConfirm

          public static void renameWithConfirm(java.io.File from,
                                               java.io.File 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(java.io.File file)

    - #### isContained

          public static boolean isContained(java.io.File folder,
                                            java.io.File file)

      Return true if file is contained in folder

    - #### getRelativePath

          public static java.lang.String getRelativePath(java.lang.String basePath,
                                                         java.lang.String path)

      Convert absolute path into a path relative to the base path

    - #### clean

          public static void clean(java.nio.ByteBuffer buffer)

    - #### createDirectory

          public static void createDirectory(java.lang.String directory)

    - #### createDirectory

          public static void createDirectory(java.io.File directory)

    - #### delete

          public static boolean delete(java.lang.String file)

    - #### delete

          public static void delete(java.io.File... files)

    - #### deleteAsync

          public static void deleteAsync(java.lang.String file)

    - #### visitDirectory

          public static void visitDirectory(java.nio.file.Path dir,
                                            java.util.function.Predicate<? super java.io.File> filter,
                                            java.util.function.Consumer<? super java.io.File> consumer)

    - #### stringifyFileSize

          public static java.lang.String stringifyFileSize(double value)

    - #### deleteRecursive

          public static void deleteRecursive(java.io.File dir)

      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

          public static void deleteRecursiveOnExit(java.io.File dir)

      Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.
      Parameters:
        `dir` - Directory to be deleted

    - #### handleCorruptSSTable

          public static void handleCorruptSSTable(CorruptSSTableException e)

    - #### handleFSError

          public static void handleFSError(FSError e)

    - #### folderSize

          public static long folderSize(java.io.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

    - #### copyTo

          public static void copyTo(java.io.DataInput in,
                                    java.io.OutputStream out,
                                    int length)
                             throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### isSubDirectory

          public static boolean isSubDirectory(java.io.File parent,
                                               java.io.File child)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### append

          public static void append(java.io.File file,
                                    java.lang.String... lines)

    - #### appendAndSync

          public static void appendAndSync(java.io.File file,
                                           java.lang.String... lines)

    - #### replace

          public static void replace(java.io.File file,
                                     java.lang.String... lines)

    - #### write

          public static void write(java.io.File file,
                                   java.util.List<java.lang.String> lines,
                                   java.nio.file.StandardOpenOption... options)

    - #### readLines

          public static java.util.List<java.lang.String> readLines(java.io.File file)

    - #### setFSErrorHandler

          public static void setFSErrorHandler(FSErrorHandler handler)

    - #### getTotalSpace

          public static long getTotalSpace(java.io.File file)

      Returns the size of the specified partition.

      This method handles large file system by returning `Long.MAX_VALUE` if the size overflow. See JDK-8179320 for more information.

      Parameters:
        `file` - the partition
      Returns:
        the size, in bytes, of the partition or `0L` if the abstract pathname does not name a partition

    - #### getFreeSpace

          public static long getFreeSpace(java.io.File file)

      Returns the number of unallocated bytes on the specified partition.

      This method handles large file system by returning `Long.MAX_VALUE` if the number of unallocated bytes overflow. See JDK-8179320 for more information

      Parameters:
        `file` - the partition
      Returns:
        the number of unallocated bytes on the partition or `0L` if the abstract pathname does not name a partition.

    - #### getUsableSpace

          public static long getUsableSpace(java.io.File file)

      Returns the number of available bytes on the specified partition.

      This method handles large file system by returning `Long.MAX_VALUE` if the number of available bytes overflow. See JDK-8179320 for more information

      Parameters:
        `file` - the partition
      Returns:
        the number of available bytes on the partition or `0L` if the abstract pathname does not name a partition.

    - #### getFileStore

          public static java.nio.file.FileStore getFileStore(java.nio.file.Path path)
                                                      throws java.io.IOException

      Returns the `FileStore` representing the file store where a file is located. This `FileStore` handles large file system by returning `Long.MAX_VALUE` from `FileStore#getTotalSpace()`, `FileStore#getUnallocatedSpace()` and `FileStore#getUsableSpace()` it the value is bigger than `Long.MAX_VALUE`. See JDK-8162520 for more information.
      Parameters:
        `path` - the path to the file
      Returns:
        the file store where the file is stored
      Throws:
        `java.io.IOException`

Copyright © 2018 The Apache Software Foundation