Class BambooFilenameUtils


  • public class BambooFilenameUtils
    extends Object
    • Method Detail

      • isPathAbsolute

        public static boolean isPathAbsolute​(String path)
        Test if path denotes absolute path. Method is platform specific. For Windows and Linux it will return different results.
        Parameters:
        path - path to be verified
        Returns:
        true if path is absolute
      • doesPathFollowToParentDirectory

        public static boolean doesPathFollowToParentDirectory​(String path)
        Test if path "escapes" current directory
        Parameters:
        path - path to be verified
        Returns:
        true if path "escapes" current directory
      • getScriptSuffix

        public static String getScriptSuffix()
        Returns:
        script extension used on the current platform
      • getShortWindowsPath

        public static io.atlassian.fugue.Either<String,​File> getShortWindowsPath​(String path)
        Returns a short 8.3 path for a given path. If it's not possible, the parameter path is returned as is. Only converts the path on Windows. The input path has to exist. The method shells out to cmd, so you should cache the returned value. On systems other than Windows, it will only perform the existence check and just return the supplied path.
        Parameters:
        path - path to convert to 8.3
        Returns:
        converted path or an error message if the conversion was unsuccesful
        Throws:
        IllegalArgumentException - if the input path does not exist
      • shortenNameIfPossible

        @NotNull
        public static @NotNull File shortenNameIfPossible​(@NotNull
                                                          @NotNull File file)
        Shortens name to 8.3 on Windows on best effort basis. It will return the same name if shortening didn't work.
      • shortenNameIfPossible

        @NotNull
        public static @NotNull Path shortenNameIfPossible​(@NotNull
                                                          @NotNull Path file)
        Shortens name to 8.3 on Windows on best effort basis. It will return the same name if shortening didn't work.
      • makeTempFileName

        @NotNull
        public static @NotNull String makeTempFileName​(@NotNull
                                                       @NotNull String prefix,
                                                       @Nullable
                                                       @Nullable String suffix)
        Creates a temp file name in prefix + random number + suffix format. If no suffix is given, ".tmp" will be used.
      • stripTrailingSlashes

        @Nullable
        public static @Nullable String stripTrailingSlashes​(@Nullable
                                                            @Nullable String path)
        Strip trailing slashes from path
      • containsDirectoryTraversalString

        public static boolean containsDirectoryTraversalString​(@Nullable
                                                               @Nullable String name)
        Basic validation of a String to see if it contains directory traversal chars. Prefer using BambooFileUtils.newFileUnderParent(File, String) but can use when that is not practical