Class PathUtils


  • public final class PathUtils
    extends java.lang.Object
    Utility methods for Path.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addRemovePathHook​(java.nio.file.Path path)
      Adds a hook to the shutdown event of the JVM which will delete all files and directories at the given path (inclusive) when the JVM exits.
      static java.nio.file.Path createTmpDirToRemoveOnShutdown​(java.lang.String prefix)  
      static java.nio.file.Path createTmpToRemoveOnShutdown​(java.lang.String prefix)  
      static void deleteRecursivelyIfExists​(java.nio.file.Path path)
      Deletes a file or a directory if it exists.
      static java.util.List<java.nio.file.Path> getClassPathItems​(java.lang.String classPath)  
      static java.lang.String toSystemIndependentPath​(java.nio.file.Path path)
      Returns a system-independent path.
      • Methods inherited from class java.lang.Object

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

      • deleteRecursivelyIfExists

        public static void deleteRecursivelyIfExists​(@NonNull
                                                     java.nio.file.Path path)
                                              throws java.io.IOException
        Deletes a file or a directory if it exists. If the directory is not empty, its contents will be deleted recursively. Symbolic links to files or directories will be removed, but the files or directories they link will not be altered. See https://issuetracker.google.com/71843178
        Parameters:
        path - the file or directory to delete. The file/directory may not exist; if the directory exists, it may be non-empty.
        Throws:
        java.io.IOException
      • toSystemIndependentPath

        @NonNull
        public static java.lang.String toSystemIndependentPath​(@NonNull
                                                               java.nio.file.Path path)
        Returns a system-independent path.
      • createTmpToRemoveOnShutdown

        @NonNull
        public static java.nio.file.Path createTmpToRemoveOnShutdown​(@NonNull
                                                                     java.lang.String prefix)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • createTmpDirToRemoveOnShutdown

        @NonNull
        public static java.nio.file.Path createTmpDirToRemoveOnShutdown​(@NonNull
                                                                        java.lang.String prefix)
                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getClassPathItems

        @NonNull
        public static java.util.List<java.nio.file.Path> getClassPathItems​(@NonNull
                                                                           java.lang.String classPath)
      • addRemovePathHook

        public static void addRemovePathHook​(@NonNull
                                             java.nio.file.Path path)
        Adds a hook to the shutdown event of the JVM which will delete all files and directories at the given path (inclusive) when the JVM exits.
        Parameters:
        path - the path to delete