Class FilesUtils


  • public class FilesUtils
    extends Object
    Files utilities.
    • Method Detail

      • getCachePathSetting

        public static String getCachePathSetting()
      • setCachePathSetting

        public static void setCachePathSetting​(String cachePathSetting)
      • resetDeployPath

        public static void resetDeployPath()
        Public for test purposes
      • normalizePath

        public static String normalizePath​(String pathString)
        Given a file path as a string, will normalize it and return the normalized string if valid, or null if not. The '~' home symbol will be converted into the actual home path. Slashes will be corrected depending on the OS.
      • getDeployedPath

        public static Path getDeployedPath​(Path path)
                                    throws IOException
        Returns the deployed path from the given path.
        Parameters:
        path - the path
        Returns:
        the deployed path from the given path.
        Throws:
        IOException
      • saveToFile

        public static void saveToFile​(InputStream in,
                                      Path outFile)
                               throws IOException
        Save the given input stream in in the give out file outFile
        Parameters:
        in - the input stream
        outFile - the output file
        Throws:
        IOException
      • saveToFile

        public static void saveToFile​(String content,
                                      Path outFile)
                               throws IOException
        Save the given String content in the give out file outFile
        Parameters:
        content - the string content
        outFile - the output file
        Throws:
        IOException
      • getOffsetAfterScheme

        public static int getOffsetAfterScheme​(String uri)
      • getFilePathSlash

        public static String getFilePathSlash​(String text)
        Returns the slash ("/" or "\") that is used by the given string. If no slash is given "/" is returned by default.
        Parameters:
        text -
        Returns:
      • convertToWindowsPath

        public static String convertToWindowsPath​(String pathString)
        Ensures there is no slash before a drive letter, and forces use of '\'
        Parameters:
        pathString -
        Returns:
      • pathEndsWithFile

        public static boolean pathEndsWithFile​(String pathString)
      • isIncludedInDeployedPath

        public static boolean isIncludedInDeployedPath​(Path resourceCachePath)
      • removeFileScheme

        public static String removeFileScheme​(String fileURI)
        Remove the file:// scheme from the given file URI.
        Parameters:
        fileURI - the file URI.
        Returns:
        the file URI without file scheme.
      • toFile

        public static File toFile​(String fileUri)
        Convert the given file Uri to a File.
        Parameters:
        fileUri - the file Uri.
        Returns:
        the given file Uri to a File.
      • getPath

        public static Path getPath​(String uri)
        Returns the IO Path from the given uri. This URI can use several syntaxes like:
        • file:///C:/folder (Windows OS), file://home (Linux OS)
        • a%20b/folder (folder with spaces)
        Parameters:
        uri - the URI
        Returns:
        the IO Path from the given uri.
      • encodePath

        public static String encodePath​(String path)
        Replace spaces with "%20".
        Parameters:
        path - the path.
        Returns:
        the path with replaced spaces.
      • readString

        public static String readString​(Path path)
                                 throws IOException
        Very simple implementation of reading all content from a file into a string using the UTF-8 charset. Uses the System's line separator. Not suited for reading large files.
        Parameters:
        path - the path to a readable file.
        Returns:
        the contents of the file.
        Throws:
        IOException - if an error occurred while reading the file.
      • isValidPath

        public static boolean isValidPath​(Path path)
        Returns true if the file at the given path exists.
        Parameters:
        path - the path.
        Returns:
        true if the file at the given path exists.
      • getFileName

        public static String getFileName​(Path path)
        Returns the file name of the given path.
        Parameters:
        path - the path.
        Returns:
        the file name of the given path.