public class BambooFileUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static com.google.common.base.Supplier<File> |
JAVA_IO_SHORT_TMPDIR
The value of
SystemUtils.JAVA_IO_TMPDIR. |
| Modifier and Type | Method and Description |
|---|---|
static String |
calculateRelativePath(File directory,
File file)
Calculates a relative path to a file from the given directory.
|
static boolean |
contains(File file,
Pattern pattern)
This method checks whether given pattern occurs in a file.
|
static boolean |
containsRegex(File file,
String regexToMatch)
Convenience method.
|
static void |
createDirectoryIfNotExists(File directory)
Create directory if not present.
|
static com.google.common.base.Supplier<File> |
createDirectorySupplier(File directory) |
static com.google.common.base.Supplier<File> |
createDirectorySupplier(com.google.common.base.Supplier<File> delegate)
Supplies directory.
|
static void |
createFileWithSize(File file,
long size)
Creates a file of exact size (in bytes).
|
static File |
createSafeTempFile(String name,
File dir)
Deprecated.
since 5.4 use
SecureTemporaryFiles class |
static File |
createSafeTempFile(String prefix,
String suffix)
Deprecated.
since 5.4 use
SecureTemporaryFiles class |
static File |
createSafeTempFile(String prefix,
String suffix,
File dir)
Deprecated.
since 5.4 use
SecureTemporaryFiles class |
static File |
createTempDirectory(File parentDir,
String prefix)
Create a temporary directory in specified location.
|
static File |
createTempDirectory(Object client) |
static File |
createTempDirectory(String prefix) |
static File |
getSharedTemporaryFile(SharedTemporaryFiles.SharedTemporaryFileSpec temporaryFileSpec)
Deprecated.
|
static File |
getSharedTemporaryFile(String content,
String prefix,
String suffix,
boolean executable,
File directory)
Deprecated.
|
static boolean |
isContainsDirectoryTraversalString(String name)
Deprecated.
since 5.10 use
BambooFilenameUtils.containsDirectoryTraversalString(String) |
static boolean |
isDirectoryImportant(File directory)
Checks a path against a defined list of directories to see if it is important (and should not be deleted)
|
static boolean |
isDirectoryOrLinkToDirectory(File file)
Checks whether a
File is a directory or a link to a directory. |
static void |
moveDirectoryContentToDirectory(File src,
File destDir,
boolean createDestDir)
Moves directory content to destination directory.
|
static File |
newFileUnderParent(File parent,
String child)
Fulfills the general contract of
File.File(java.io.File, String). |
static String |
pathFromComponents(String... pathComponents) |
static com.google.common.base.Supplier<File> |
persistentFileSupplier(com.google.common.base.Supplier<File> fileSupplier)
Supplies Files.
|
static org.apache.commons.io.filefilter.IOFileFilter |
regexPathFilter(String pathPattern)
Returns an
IOFileFilter that performs a full path match against the supplied pattern. |
static String |
relativizePath(File rootDirectory,
File workingDirectory,
String path)
Given parent and child directories, and a path relative to parent directory, return path relative to the child directory.
|
static void |
renameTo(File from,
File to)
Renames a file or directory.
|
static File |
safeNewFile(String path) |
static File |
safeWriteStringToFile(String string,
String prefix,
String suffix,
File directory)
Writes a string to a newly created temporary file in as safe manner as possible.
|
static boolean |
setExecutableByOwnerOnly(File file)
Sets the file permissions so that only the owner can execute a file
|
static boolean |
setReadableByOwnerOnly(File file)
Sets the file permissions so that only the owner can read from a file
|
static boolean |
setWritableByOwnerOnly(File file)
Sets the file permissions so that only the owner can write to a file
|
static List<String> |
splitPathToComponents(String path) |
public static final com.google.common.base.Supplier<File> JAVA_IO_SHORT_TMPDIR
SystemUtils.JAVA_IO_TMPDIR. On Windows, it will be shortened to 8.3 format.public static boolean isDirectoryImportant(@Nullable
File directory)
directory - public static boolean isDirectoryOrLinkToDirectory(File file)
File is a directory or a link to a directory.file - File expected to be a directory.public static File createTempDirectory(@NotNull Object client) throws IOException
IOExceptionpublic static File createTempDirectory(@Nullable File parentDir, @NotNull String prefix) throws IOException
parentDir - null indicates default tmp directoryprefix - filename prefixIOExceptionpublic static File createTempDirectory(@NotNull String prefix) throws IOException
IOException@Deprecated public static File createSafeTempFile(@NotNull String name, @Nullable File dir) throws IOException
SecureTemporaryFiles classIOException@Deprecated public static File createSafeTempFile(@NotNull String prefix, @Nullable String suffix) throws IOException
SecureTemporaryFiles classprefix - suffix - IOExceptionjava.io.File#createTempFile} and {@link #createSafeTempFile(String, java.io.File)}}@Deprecated public static File createSafeTempFile(@NotNull String prefix, @Nullable String suffix, @Nullable File dir) throws IOException
SecureTemporaryFiles classprefix - suffix - IOExceptionjava.io.File#createTempFile} and {@link #createSafeTempFile(String, java.io.File)}}public static boolean setWritableByOwnerOnly(File file)
file - public static boolean setReadableByOwnerOnly(File file)
file - public static boolean setExecutableByOwnerOnly(File file)
file - @NotNull public static File safeWriteStringToFile(@NotNull String string, @NotNull String prefix, @Nullable String suffix, @Nullable File directory) throws IOException
string - the string to writeIOExceptionFile#createTempFile(String, String, File))@NotNull public static List<String> splitPathToComponents(@NotNull String path)
@NotNull public static String pathFromComponents(@NotNull String... pathComponents)
public static boolean contains(File file, Pattern pattern) throws IOException
file - the file to checkpattern - the pattern to search forIOException - in case of file access problemspublic static boolean containsRegex(@NotNull
File file,
@NotNull
String regexToMatch)
throws IOException
IOExceptioncontains(File, Pattern)public static String relativizePath(@NotNull File rootDirectory, @NotNull File workingDirectory, @Nullable String path)
rootDirectory - root directoryworkingDirectory - working directory (must be inside root directory)path - path relative to root directorypublic static String calculateRelativePath(@NotNull File directory, @NotNull File file)
directory: /home/user/
file: /home/user/documents/credits.txt
...
relative path: documents/credits.txt
directory - the directory from which the path should be calculatedfile - the file to which the path should be calculated; can be a directory toopublic static void renameTo(File from, File to) throws IOException
from - the source file/directoryto - the new location of source fileIOException - if the destination file/directory already exists or move operation fails for other reasonpublic static void moveDirectoryContentToDirectory(@NotNull
File src,
@NotNull
File destDir,
boolean createDestDir)
throws IOException
src - - the directory which content should be moveddestDir - - the destination directorycreateDestDir - - If true create the destination directory, otherwise if false throw an IOExceptionNullPointerException - - if source or destination is nullorg.apache.commons.io.FileExistsException - - if the directory or file exists in the destination directoryIOException - - if source or destination is invalidIOException - - if an IO error occurs moving the file@Deprecated public static File getSharedTemporaryFile(@NotNull String content, @NotNull String prefix, @Nullable String suffix, boolean executable, @Nullable File directory) throws IOException
SharedTemporaryFiles.create(com.atlassian.bamboo.util.SharedTemporaryFiles.SharedTemporaryFileSpec)content - the content that the file should haveprefix - the file name prefixsuffix - the file name suffixexecutable - whether or not make the file executabledirectory - the directory in which to create file (temp directory unless specified otherwise)IOException@Deprecated public static File getSharedTemporaryFile(@NotNull SharedTemporaryFiles.SharedTemporaryFileSpec temporaryFileSpec) throws IOException
SharedTemporaryFiles.create(com.atlassian.bamboo.util.SharedTemporaryFiles.SharedTemporaryFileSpec)temporaryFileSpec - the directory in which to create file (temp directory unless specified otherwise)IOExceptionpublic static com.google.common.base.Supplier<File> persistentFileSupplier(com.google.common.base.Supplier<File> fileSupplier)
public static com.google.common.base.Supplier<File> createDirectorySupplier(com.google.common.base.Supplier<File> delegate)
public static com.google.common.base.Supplier<File> createDirectorySupplier(File directory)
public static org.apache.commons.io.filefilter.IOFileFilter regexPathFilter(@NotNull
String pathPattern)
IOFileFilter that performs a full path match against the supplied pattern.public static File newFileUnderParent(@NotNull File parent, @NotNull String child) throws IOException
File.File(java.io.File, String). The returned file is always
in canonical format and always rooted under the parent argument. Attempts to traverse out of the parent directory
will result in IllegalArgumentException being thrown.parent - parent directorychild - child under parent directory. Relative paths are allowed as long as the result is under the parent directoryIOException - if a problem occurred during directory tree access@Deprecated public static boolean isContainsDirectoryTraversalString(@Nullable String name)
BambooFilenameUtils.containsDirectoryTraversalString(String)newFileUnderParent(File, String)
but can use when that is not practicalpublic static void createFileWithSize(@NotNull
File file,
long size)
throws IOException
file - file to createsize - size of the file (in bytes)IOExceptionpublic static void createDirectoryIfNotExists(File directory) throws IllegalStateException
directory - to be createdIllegalStateException - if directory can't be createdCopyright © 2016 Atlassian Software Systems Pty Ltd. All rights reserved.