Class FileUtil


  • public class FileUtil
    extends java.lang.Object
    A file utility class
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] createChecksum​(java.io.File filename, java.lang.String digestAlgorithm)  
      static void createSymlink​(java.lang.String targetPathStr, java.io.File symlinkFile)  
      static LimitedDosFileAttributes dosAttrsFromString​(java.lang.String dosFileAttributes)  
      static java.lang.String dosAttrsToString​(java.nio.file.attribute.DosFileAttributes dosFileAttributes)  
      static boolean exists​(java.io.File file)
      Replaces the exists() method in the File class by taking symlinks into account.
      static java.lang.String formatFileSize​(long size)  
      static java.io.File getCanonicalFile​(java.io.File file)  
      static java.lang.String getDatabasePath​(java.lang.String filePath)  
      static java.lang.String getRelativeDatabasePath​(java.io.File base, java.io.File file)  
      static java.lang.String getRelativePath​(java.io.File base, java.io.File file)  
      static boolean isDirectory​(java.io.File file)  
      static boolean isFileLocked​(java.io.File file)  
      static boolean isSymlink​(java.io.File file)  
      static java.lang.String readSymlinkTarget​(java.io.File file)  
      static java.lang.String removeTrailingSlash​(java.lang.String filename)  
      • Methods inherited from class java.lang.Object

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

      • getRelativePath

        public static java.lang.String getRelativePath​(java.io.File base,
                                                       java.io.File file)
      • getRelativeDatabasePath

        public static java.lang.String getRelativeDatabasePath​(java.io.File base,
                                                               java.io.File file)
      • getDatabasePath

        public static java.lang.String getDatabasePath​(java.lang.String filePath)
      • removeTrailingSlash

        public static java.lang.String removeTrailingSlash​(java.lang.String filename)
      • getCanonicalFile

        public static java.io.File getCanonicalFile​(java.io.File file)
      • createChecksum

        public static byte[] createChecksum​(java.io.File filename,
                                            java.lang.String digestAlgorithm)
                                     throws java.security.NoSuchAlgorithmException,
                                            java.io.IOException
        Throws:
        java.security.NoSuchAlgorithmException
        java.io.IOException
      • isFileLocked

        public static boolean isFileLocked​(java.io.File file)
      • isSymlink

        public static boolean isSymlink​(java.io.File file)
      • readSymlinkTarget

        public static java.lang.String readSymlinkTarget​(java.io.File file)
      • createSymlink

        public static void createSymlink​(java.lang.String targetPathStr,
                                         java.io.File symlinkFile)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • dosAttrsToString

        public static java.lang.String dosAttrsToString​(java.nio.file.attribute.DosFileAttributes dosFileAttributes)
      • exists

        public static boolean exists​(java.io.File file)
        Replaces the exists() method in the File class by taking symlinks into account. The method returns true if the file exists, false otherwise.

        Note: The method returns true, if a symlink exists, but points to a non-existing target. This behavior is different from the classic exists()-method in the File class.

        Parameters:
        file - A file
        Returns:
        Returns true if a file exists (even if its symlink target does not), false otherwise
      • isDirectory

        public static boolean isDirectory​(java.io.File file)
      • formatFileSize

        public static java.lang.String formatFileSize​(long size)