Class FileUtil


  • public final class FileUtil
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FileUtil.FilesWatchdog
      It stores all created files and directory.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean ENABLE_WATCHDOG
      Enable FilesWatchdog function.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @lombok.NonNull boolean createDir​(@NonNull java.nio.file.Path path, boolean... ifNotExists)
      Create all necessary directories if not exists.
      static @lombok.NonNull boolean createFile​(@NonNull java.nio.file.Path path, boolean... ifNotExists)
      Create all necessary directories and file.
      static @NonNull java.nio.file.Path getClassPathMainDir()
      Get root directory with classes.
      static FileUtil.FilesWatchdog getFilesWatchdog()
      Get single FileUtil.FilesWatchdog for all create operation in this utility class FileUtil.
      static java.nio.file.Path getUserDir()
      Get User directory.
      static boolean isAbsolute​(java.lang.String candidate)
      Check if candidate string is valid absolute path in current file system.
      static boolean isUserDirRelative​(java.lang.String candidate)
      Check if candidate string is valid path from user directory.
      • Methods inherited from class java.lang.Object

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

      • ENABLE_WATCHDOG

        public static boolean ENABLE_WATCHDOG
        Enable FilesWatchdog function. Default is false.
    • Method Detail

      • getClassPathMainDir

        @NonNull
        public static @NonNull java.nio.file.Path getClassPathMainDir()
        Get root directory with classes.
        Returns:
        root directory with classes.
      • createFile

        @NonNull
        public static @lombok.NonNull boolean createFile​(@NonNull
                                                         @NonNull java.nio.file.Path path,
                                                         boolean... ifNotExists)
        Create all necessary directories and file.
        Parameters:
        path - file to create.
        ifNotExists - true - check if exists before creating / null or false - don't check and remove old file.
        Returns:
        true - File has been created / false - not
      • createDir

        @NonNull
        public static @lombok.NonNull boolean createDir​(@NonNull
                                                        @NonNull java.nio.file.Path path,
                                                        boolean... ifNotExists)
        Create all necessary directories if not exists.
        Parameters:
        path - directory to create.
        ifNotExists - true - check if exists before creating / null or false - don't check and remove if it was a file
        Returns:
        true - Directory has been created / false - not
      • isAbsolute

        public static boolean isAbsolute​(@Nullable
                                         java.lang.String candidate)
        Check if candidate string is valid absolute path in current file system. Null safe.
        Parameters:
        candidate - absolute path.
        Returns:
        true - it's absolute path.
      • isUserDirRelative

        public static boolean isUserDirRelative​(@Nullable
                                                java.lang.String candidate)
        Check if candidate string is valid path from user directory. Null safe.
        Parameters:
        candidate - relative path from user directory.
        Returns:
        true - it's path from user directory.
      • getUserDir

        public static java.nio.file.Path getUserDir()
        Get User directory. It's root project directory or directory where this application has been started.
        Returns:
        Path to user directory.