Package com.atlassian.bamboo.utils
Class BambooPathUtils
java.lang.Object
com.atlassian.bamboo.utils.BambooPathUtils
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanDirectory(@NotNull Path directoryToCleanOrSymlink) Cleans the specified directory by deleting all files and subdirectories within it Similar toFileUtils.cleanDirectory(File)but operates onPathAttempts to delete all contents of the directory and retries if aDirectoryNotEmptyExceptionoccurs.static booleancontentEquals(@NotNull Path file1, @NotNull Path file2) Deprecated.since 11.0, without replacementstatic voiddeleteDirectory(@NotNull Path path) protected static voiddeleteNoThrow(Path file, AtomicReference<IOException> exceptionRef) static booleandeleteQuietly(@Nullable Path path) static voidforceDelete(@NotNull Path path) static OutputStreamopenOutputStream(Path file) static OutputStreamopenOutputStream(Path file, boolean append) static StringreadFileToString(Path path, Charset encoding) static @Nullable Pathstatic PathtoRealPathIfNeeded(@NotNull Path maybeSymlink) Returns a fully dereferenced path (including hardlinks) if the supplied argument is a symlink.static voidwriteStringToFile(Path file, String data, Charset charset)
-
Constructor Details
-
BambooPathUtils
public BambooPathUtils()
-
-
Method Details
-
deleteQuietly
- See Also:
-
cleanDirectory
public static void cleanDirectory(@NotNull @NotNull Path directoryToCleanOrSymlink) throws IOException Cleans the specified directory by deleting all files and subdirectories within it Similar toFileUtils.cleanDirectory(File)but operates onPathAttempts to delete all contents of the directory and retries if aDirectoryNotEmptyExceptionoccurs. 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:
-
deleteDirectory
- Throws:
IOException- See Also:
-
forceDelete
- Throws:
IOException- See Also:
-
deleteNoThrow
@VisibleForTesting protected static void deleteNoThrow(Path file, AtomicReference<IOException> exceptionRef) -
toRealPathIfNeeded
Returns a fully dereferenced path (including hardlinks) if the supplied argument is a symlink.- Throws:
IOException
-
writeStringToFile
- Throws:
IOException- See Also:
-
toPath
-
openOutputStream
- Throws:
IOException- See Also:
-
openOutputStream
- Throws:
IOException- See Also:
-
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:
-
readFileToString
- Throws:
IOException- See Also:
-