Package ch.cern.dirq

Class FileUtils

java.lang.Object
ch.cern.dirq.FileUtils

public final class FileUtils extends Object
Convenient file related utilities.
This is a private class to be used only by the directory queue classes. Its API can change at any time without any notice.
  • Field Details

  • Constructor Details

    • FileUtils

      private FileUtils()
  • Method Details

    • isSet

      private static boolean isSet(int perm, int bit)
    • posixPermissionsFromInteger

      public static Set<PosixFilePermission> posixPermissionsFromInteger(int perm)
      Create NIO POSIX file permissions from numerical POSIX permissions.
      Parameters:
      perm - numerical permissions
      Returns:
      file permissions
    • fileAttributesFromInteger

      public static FileAttribute<?> fileAttributesFromInteger(int perm)
      Create NIO file attributes from numerical POSIX permissions.
      Parameters:
      perm - numerical permissions
      Returns:
      file attributes
    • fileKey

      public static String fileKey(File file) throws IOException
      Return a unique string identifying the given file object.
      Parameters:
      file - file object
      Returns:
      unique string
      Throws:
      IOException - if any file operation fails
    • fileKey

      public static String fileKey(String path) throws IOException
      Return a unique string identifying the given path string.
      Parameters:
      path - file path string
      Returns:
      unique string
      Throws:
      IOException - if any file operation fails
    • fileKey

      public static String fileKey(Path path) throws IOException
      Return a unique string identifying the given path object.
      Parameters:
      path - file path object
      Returns:
      unique string
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(File file, String data) throws IOException
      Write a UTF-8 string to a file object.
      Parameters:
      file - file object
      data - UTF-8 string
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(String path, String data) throws IOException
      Write a UTF-8 string to a path string.
      Parameters:
      path - file path string
      data - UTF-8 string
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(Path path, String data) throws IOException
      Write a UTF-8 string to a path object.
      Parameters:
      path - file path object
      data - UTF-8 string
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(File file, byte[] data) throws IOException
      Write bytes to a file object.
      Parameters:
      file - file object
      data - bytes
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(String path, byte[] data) throws IOException
      Write bytes to a path string.
      Parameters:
      path - file path string
      data - bytes
      Throws:
      IOException - if any file operation fails
    • writeToFile

      public static void writeToFile(Path path, byte[] data) throws IOException
      Write bytes to a path object.
      Parameters:
      path - file path object
      data - bytes
      Throws:
      IOException - if any file operation fails
    • readToString

      public static String readToString(File file) throws IOException
      Read a UTF-8 string from a file object.
      Parameters:
      file - file object
      Returns:
      UTF-8 string
      Throws:
      IOException - if any file operation fails
    • readToString

      public static String readToString(String path) throws IOException
      Read a UTF-8 string from a path string.
      Parameters:
      path - file path string
      Returns:
      UTF-8 string
      Throws:
      IOException - if any file operation fails
    • readToString

      public static String readToString(Path path) throws IOException
      Read a UTF-8 string from a path object.
      Parameters:
      path - file path object
      Returns:
      UTF-8 string
      Throws:
      IOException - if any file operation fails
    • readToByteArray

      public static byte[] readToByteArray(File file) throws IOException
      Read all the bytes from a file object.
      Parameters:
      file - file object
      Returns:
      bytes
      Throws:
      IOException - if any file operation fails
    • readToByteArray

      public static byte[] readToByteArray(String path) throws IOException
      Read all the bytes from a path string.
      Parameters:
      path - file path string
      Returns:
      bytes
      Throws:
      IOException - if any file operation fails
    • readToByteArray

      public static byte[] readToByteArray(Path path) throws IOException
      Read all the bytes from a path object.
      Parameters:
      path - file path object
      Returns:
      bytes
      Throws:
      IOException - if any file operation fails
    • recursiveDelete

      public static boolean recursiveDelete(File path)
      Recursively delete the given path, stopping on the first error.
      Parameters:
      path - file object
      Returns:
      true if delete succeeded