Class SafeFileTools

java.lang.Object
com.atlassian.bamboo.file.SafeFileTools

public class SafeFileTools extends Object
A set of static methods that fives access to secure operations on file without returning the File object.
Since:
12.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canRead(@NotNull String path)
    Tests whether the file denoted by this abstract pathname is readable.
    static boolean
    canWrite(@NotNull String path)
    Tests whether the file denoted by this abstract pathname is writable.
    static boolean
    exists(@NotNull String path)
    Tests whether the file denoted by this abstract pathname exists.
    static String
    Returns the canonical path of the file.
    static String
    Returns the parent path of the file.
    static boolean
    hasParent(@NotNull String path)
    Tests whether the file denoted by this abstract pathname has a parent.
    static boolean
    Tests if this abstract pathname is absolute.
    static boolean
    Tests whether the file denoted by this abstract pathname is a directory.
    static boolean
    isFile(@NotNull String path)
    Tests whether the file denoted by this abstract pathname is a regular file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SafeFileTools

      public SafeFileTools()
  • Method Details

    • getCanonicalPath

      public static String getCanonicalPath(String path) throws IOException
      Returns the canonical path of the file. This method wraps a call to File.getCanonicalPath() so that all file operations are in this class.
      Parameters:
      path - the file to get the canonical path for
      Returns:
      the canonical path of the file
      Throws:
      IOException
    • isAbsolute

      public static boolean isAbsolute(String path)
      Tests if this abstract pathname is absolute. This method wraps a call to File.isAbsolute() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if this abstract pathname is absolute, false otherwise
    • isDirectory

      public static boolean isDirectory(String path)
      Tests whether the file denoted by this abstract pathname is a directory. This method wraps a call to File.isDirectory() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
    • exists

      public static boolean exists(@NotNull @NotNull String path)
      Tests whether the file denoted by this abstract pathname exists. This method wraps a call to File.exists() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname exists; false otherwise
    • canWrite

      public static boolean canWrite(@NotNull @NotNull String path)
      Tests whether the file denoted by this abstract pathname is writable. This method wraps a call to File.canWrite() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is writable; false otherwise
    • canRead

      public static boolean canRead(@NotNull @NotNull String path)
      Tests whether the file denoted by this abstract pathname is readable. This method wraps a call to File.canRead() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is readable; false otherwise
    • isFile

      public static boolean isFile(@NotNull @NotNull String path)
      Tests whether the file denoted by this abstract pathname is a regular file. This method wraps a call to File.isFile() so that all file operations are in this class.
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is a regular file; false otherwise
    • hasParent

      public static boolean hasParent(@NotNull @NotNull String path)
      Tests whether the file denoted by this abstract pathname has a parent. This method wraps a call to File.getParent() so that all file operations are in this class. Examples:
        - /path/to/file.txt -> true
        - /path/to/ -> true
        - /path/to -> true
        - /path/to/file.txt/ -> true
        - /file.txt -> true
        - /path/ -> true
        - path/file.txt -> true
        - ./file.txt -> true
        - / -> false
        - file.txt -> false
      
      Parameters:
      path - the file to test
      Returns:
      true if and only if the file denoted by this abstract pathname has a parent; false otherwise
    • getParentPath

      public static String getParentPath(String path)
      Returns the parent path of the file. This method wraps a call to File.getParentFile() so that all file operations are in this class.
      Parameters:
      path - the file to get the parent path for
      Returns:
      the parent path of the file