Class BambooPathUtils

java.lang.Object
com.atlassian.bamboo.utils.BambooPathUtils

public class BambooPathUtils extends Object
Provides functionality equivalent to Apache FileUtils, but on Paths. Do not add methods that do not exist in Apache class to this class, use BambooFiles instead.

Any change to this class should pass a full suite of Apache Commons IO unit tests. See https://hello.atlassian.net/wiki/spaces/BAMBOO/pages/141524177/Testing+BambooPathUtils+against+Apache+Commons+IO+unit+tests for details

  • Constructor Details

    • BambooPathUtils

      public BambooPathUtils()
  • Method Details

    • deleteQuietly

      public static boolean deleteQuietly(@Nullable @Nullable Path path)
      See Also:
      • FileUtils.deleteQuietly(File)
    • cleanDirectory

      public static void cleanDirectory(@NotNull @NotNull Path directoryToCleanOrSymlink) throws IOException
      Cleans the specified directory by deleting all files and subdirectories within it Similar to FileUtils.cleanDirectory(File) but operates on Path Attempts to delete all contents of the directory and retries if a DirectoryNotEmptyException occurs. Logs exceptions and ensures the directory is empty afterward
      Parameters:
      directoryToCleanOrSymlink - The directory to be cleaned
      Throws:
      IOException - if the directory cannot be cleaned or remains non-empty
      See Also:
      • FileUtils.cleanDirectory(File)
    • deleteDirectory

      public static void deleteDirectory(@NotNull @NotNull Path path) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.deleteDirectory(File)
    • forceDelete

      public static void forceDelete(@NotNull @NotNull Path path) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.forceDelete(File)
    • deleteNoThrow

      @VisibleForTesting protected static void deleteNoThrow(Path file, AtomicReference<IOException> exceptionRef)
    • toRealPathIfNeeded

      public static Path toRealPathIfNeeded(@NotNull @NotNull Path maybeSymlink) throws IOException
      Returns a fully dereferenced path (including hardlinks) if the supplied argument is a symlink.
      Throws:
      IOException
    • writeStringToFile

      public static void writeStringToFile(Path file, String data, Charset charset) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.writeStringToFile(File, String, Charset)
    • toPath

      @Nullable public static @Nullable Path toPath(@Nullable @Nullable File file)
    • openOutputStream

      public static OutputStream openOutputStream(Path file) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.openOutputStream(File)
    • openOutputStream

      public static OutputStream openOutputStream(Path file, boolean append) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.openOutputStream(File, boolean)
    • contentEquals

      @Deprecated public static boolean contentEquals(@NotNull @NotNull Path file1, @NotNull @NotNull Path file2) throws IOException
      Deprecated.
      since 11.0, without replacement
      Throws:
      IOException
      See Also:
      • FileUtils.contentEquals(File, File)
    • readFileToString

      public static String readFileToString(Path path, Charset encoding) throws IOException
      Throws:
      IOException
      See Also:
      • FileUtils.readFileToString(File, Charset)