public class ManFileExt extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ManFileExt.OnErrorAction
Enum that can be used to specify behaviour of the `copyRecursively()` function
in exceptional conditions.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE |
| Constructor and Description |
|---|
ManFileExt() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
copyRecursively(File thiz,
File target)
Copies this file with all its children to the specified destination [target] path.
|
static boolean |
copyRecursively(File thiz,
File target,
boolean overwrite,
java.util.function.BiFunction<File,IOException,ManFileExt.OnErrorAction> onError) |
static boolean |
copyRecursively(File thiz,
File target,
boolean overwrite,
java.util.function.BiFunction<File,IOException,ManFileExt.OnErrorAction> onError,
java.util.function.Predicate<File> filter) |
static boolean |
copyRecursively(File thiz,
File target,
java.util.function.Predicate<File> filter) |
static File |
copyTo(File thiz,
File target)
Copies this file to the given [target] file.
|
static File |
copyTo(File thiz,
File target,
boolean overwrite,
int bufferSize) |
static File |
createTempDir()
Creates an empty directory in the specified [directory], using the given [prefix] and [suffix] to generate its name.
|
static File |
createTempDir(String prefix,
String suffix,
File directory) |
static boolean |
deleteRecursively(File thiz)
Delete this file with all its children.
|
static boolean |
endsWith(File thiz,
File other)
Determines whether this file path ends with the path of [other] file.
|
static boolean |
endsWith(File thiz,
String other)
Determines whether this file belongs to the same root as [other]
and ends with all components of [other] in the same order.
|
static String |
getExtension(File thiz)
Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
|
static boolean |
isRooted(File thiz)
Determines whether this file has a root or it represents a relative path.
|
static String |
nameWithoutExtension(File thiz)
Returns file's name without an extension.
|
static File |
normalize(File thiz)
Removes all .
|
static List<File> |
normalize(List<File> segments) |
static File |
relativeTo(File thiz,
File base)
Calculates the relative path for this file from [base] file.
|
static File |
relativeToOrNull(File thiz,
File base)
Calculates the relative path for this file from [base] file.
|
static File |
relativeToOrSelf(File thiz,
File base)
Calculates the relative path for this file from [base] file.
|
static File |
resolve(File thiz,
File relative)
Adds [relative] file to this, considering this as a directory.
|
static File |
resolve(File thiz,
String relative)
Adds [relative] name to this, considering this as a directory.
|
static File |
resolveSibling(File thiz,
File relative)
Adds [relative] file to this parent directory.
|
static File |
resolveSibling(File thiz,
String relative)
Adds [relative] name to this parent directory.
|
static String |
slashPath(File thiz)
Returns [path] of this File using the invariant separator '/' to
separate the names in the name sequence.
|
static boolean |
startsWith(File thiz,
File other)
Determines whether this file belongs to the same root as [other]
and starts with all components of [other] in the same order.
|
static boolean |
startsWith(File thiz,
String other)
Determines whether this file belongs to the same root as [other]
and starts with all components of [other] in the same order.
|
static FilePathComponents |
toComponents(File thiz)
Splits the file into path components (the names of containing directories and the name of the file
itself) and returns the resulting collection of components.
|
static String |
toRelativeString(File thiz,
File base)
Calculates the relative path for this file from [base] file.
|
static FileTreeWalk |
walk(File thiz,
FileTreeWalk.FileWalkDirection direction)
Gets an iterable for visiting this directory and all its content.
|
static FileTreeWalk |
walkBottomUp(File thiz)
Gets a sequence for visiting this directory and all its content in bottom-up order.
|
static FileTreeWalk |
walkTopDown(File thiz)
Gets a sequence for visiting this directory and all its content in top-down order.
|
public static final int DEFAULT_BUFFER_SIZE
public static File createTempDir() throws IOException
If [prefix] is not specified then some unspecified name will be used. If [suffix] is not specified then ".tmp" will be used. If [directory] is not specified then the default temporary-file directory will be used.
IOException - in case of input/output error.IllegalArgumentException - if [prefix] is shorter than three symbols.public static File createTempDir(String prefix, String suffix, File directory) throws IOException
IOExceptionpublic static String getExtension(File thiz)
public static String slashPath(File thiz)
public static String nameWithoutExtension(File thiz)
public static String toRelativeString(File thiz, File base)
IllegalArgumentException - if this and base paths have different roots.public static File relativeTo(File thiz, File base)
IllegalArgumentException - if this and base paths have different roots.public static File relativeToOrSelf(File thiz, File base)
public static File relativeToOrNull(File thiz, File base)
public static FilePathComponents toComponents(File thiz)
public static boolean isRooted(File thiz)
Returns `true` when this file has non-empty root.
public static File copyTo(File thiz, File target)
If some directories on a way to the [target] are missing, they will be created. If the [target] file already exists, this function will fail unless [overwrite] argument is set to `true`.
When [overwrite] is `true` and [target] is a directory, it is replaced only if it is empty.
If this file is a directory, it is copied without its content, i.e. an empty [target] directory is created. If you want to copy directory including its contents, use [copyRecursively].
The operation doesn't preserve copied file attributes such as creation/modification date, permissions, etc.
overwrite - `true` if destination overwrite is allowed.bufferSize - the buffer size to use when copying.NoSuchFileException - if the source file doesn't exist.FileAlreadyExistsException - if the destination file already exists and 'rewrite' argument is set to `false`.IOException - if any errors occur while copying.public static boolean copyRecursively(File thiz, File target)
If this file path points to a single file, it will be copied to a file with the path [target]. If this file path points to a directory, its children will be copied to a directory with the path [target].
If the [target] already exists, it will be deleted before copying when the [overwrite] parameter permits so.
The operation doesn't preserve copied file attributes such as creation/modification date, permissions, etc.
If any errors occur during the copying, further actions will depend on the result of the call to `onError(File, IOException)` function, that will be called with arguments, specifying the file that caused the error and the exception itself. By default this function rethrows exceptions.
Exceptions that can be passed to the `onError` function:
- NoSuchFileException - if there was an attempt to copy a non-existent file - FileAlreadyExistsException - if there is a conflict - AccessDeniedException - if there was an attempt to open a directory that didn't succeed. - IOException - if some problems occur when copying.
Note that if this function fails, partial copying may have taken place.
public static boolean copyRecursively(File thiz, File target, java.util.function.Predicate<File> filter)
public static boolean copyRecursively(File thiz, File target, boolean overwrite, java.util.function.BiFunction<File,IOException,ManFileExt.OnErrorAction> onError)
public static boolean copyRecursively(File thiz, File target, boolean overwrite, java.util.function.BiFunction<File,IOException,ManFileExt.OnErrorAction> onError, java.util.function.Predicate<File> filter)
public static FileTreeWalk walk(File thiz, FileTreeWalk.FileWalkDirection direction)
direction - walk direction, top-down (by default) or bottom-up.public static FileTreeWalk walkTopDown(File thiz)
public static FileTreeWalk walkBottomUp(File thiz)
public static boolean deleteRecursively(File thiz)
public static boolean startsWith(File thiz, File other)
public static boolean startsWith(File thiz, String other)
public static boolean endsWith(File thiz, File other)
If [other] is rooted path it must be equal to this. If [other] is relative path then last N components of `this` must be the same as all components in [other], where N is the number of components in [other].
public static boolean endsWith(File thiz, String other)
public static File normalize(File thiz)
public static File resolve(File thiz, File relative)
public static File resolve(File thiz, String relative)
public static File resolveSibling(File thiz, File relative)
public static File resolveSibling(File thiz, String relative)
Copyright © 2017. All rights reserved.