Class FileSystemUtils


  • public final class FileSystemUtils
    extends java.lang.Object
    Elasticsearch utils to work with Path
    • Method Summary

      Modifier and Type Method Description
      static java.nio.file.Path append​(java.nio.file.Path base, java.nio.file.Path path, int strip)
      Appends the path to the given base and strips N elements off the path if strip is > 0.
      static void deleteSubDirectories​(java.nio.file.Path... paths)
      Deletes all subdirectories in the given path recursively
      static boolean exists​(java.nio.file.Path... files)
      Returns true iff one of the files exists otherwise false
      static java.nio.file.Path[] files​(java.nio.file.Path directory)
      Returns an array of all files in the given directory.
      static java.nio.file.Path[] files​(java.nio.file.Path directory, java.lang.String glob)
      Returns an array of all files in the given directory matching the glob.
      static java.nio.file.Path[] files​(java.nio.file.Path from, java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter)
      Returns an array of all files in the given directory matching.
      static boolean isAccessibleDirectory​(java.nio.file.Path directory, org.apache.logging.log4j.Logger logger)
      Check that a directory exists, is a directory and is readable by the current user
      static boolean isDesktopServicesStore​(java.nio.file.Path path)
      Check whether the file denoted by the given path is a desktop services store created by Finder on macOS.
      static boolean isHidden​(java.nio.file.Path path)
      Check whether the file denoted by the given path is hidden.
      static java.io.InputStream openFileURLStream​(java.net.URL url)
      Returns an InputStream the given url if the url has a protocol of 'file' or 'jar', no host, and no port.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • exists

        public static boolean exists​(java.nio.file.Path... files)
        Returns true iff one of the files exists otherwise false
      • isHidden

        public static boolean isHidden​(java.nio.file.Path path)
        Check whether the file denoted by the given path is hidden. In practice, this will check if the file name starts with a dot. This should be preferred to Files.isHidden(Path) as this does not depend on the operating system.
      • isDesktopServicesStore

        public static boolean isDesktopServicesStore​(java.nio.file.Path path)
        Check whether the file denoted by the given path is a desktop services store created by Finder on macOS.
        Parameters:
        path - the path
        Returns:
        true if the current system is macOS and the specified file appears to be a desktop services store file
      • append

        public static java.nio.file.Path append​(java.nio.file.Path base,
                                                java.nio.file.Path path,
                                                int strip)
        Appends the path to the given base and strips N elements off the path if strip is > 0.
      • deleteSubDirectories

        public static void deleteSubDirectories​(java.nio.file.Path... paths)
                                         throws java.io.IOException
        Deletes all subdirectories in the given path recursively
        Throws:
        java.lang.IllegalArgumentException - if the given path is not a directory
        java.io.IOException
      • isAccessibleDirectory

        public static boolean isAccessibleDirectory​(java.nio.file.Path directory,
                                                    org.apache.logging.log4j.Logger logger)
        Check that a directory exists, is a directory and is readable by the current user
      • openFileURLStream

        public static java.io.InputStream openFileURLStream​(java.net.URL url)
                                                     throws java.io.IOException
        Returns an InputStream the given url if the url has a protocol of 'file' or 'jar', no host, and no port.
        Throws:
        java.io.IOException
      • files

        public static java.nio.file.Path[] files​(java.nio.file.Path from,
                                                 java.nio.file.DirectoryStream.Filter<java.nio.file.Path> filter)
                                          throws java.io.IOException
        Returns an array of all files in the given directory matching.
        Throws:
        java.io.IOException
      • files

        public static java.nio.file.Path[] files​(java.nio.file.Path directory)
                                          throws java.io.IOException
        Returns an array of all files in the given directory.
        Throws:
        java.io.IOException
      • files

        public static java.nio.file.Path[] files​(java.nio.file.Path directory,
                                                 java.lang.String glob)
                                          throws java.io.IOException
        Returns an array of all files in the given directory matching the glob.
        Throws:
        java.io.IOException