public final class FileOpUtils
extends java.lang.Object
Files/FileOps.| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
append(java.io.File base,
java.lang.String... segments)
Appends the given
segments to the base file. |
static java.io.File |
append(java.lang.String base,
java.lang.String... segments)
Appends the given
segments to the base file. |
static FileOp |
create()
The standard way to create a
FileOp that interacts with the real filesystem. |
static java.io.File |
getNewTempDir(java.lang.String base,
FileOp fileOp)
Creates a new subdirectory of the system temp directory.
|
static java.io.File |
getTempDir(java.lang.String base,
int i)
Gets the temp dir corresponding to the given base and index.
|
static java.lang.String |
makeRelative(java.io.File baseDir,
java.io.File toBeRelative,
FileOp fop)
Computes a relative path from "toBeRelative" relative to "baseDir".
|
static void |
recursiveCopy(java.io.File src,
java.io.File dest,
FileOp fop,
ProgressIndicator progress)
Copies a file or directory tree to the given location.
|
static void |
retainTempDirs(java.util.Set<java.io.File> retain,
java.lang.String base,
FileOp mFop)
Delete all temp dirs with the given base except for those in
retain. |
static void |
safeRecursiveOverwrite(java.io.File src,
java.io.File dest,
FileOp fop,
ProgressIndicator progress)
Moves a file or directory from one location to another.
|
@NonNull public static FileOp create()
FileOp that interacts with the real filesystem.public static void recursiveCopy(@NonNull
java.io.File src,
@NonNull
java.io.File dest,
@NonNull
FileOp fop,
@NonNull
ProgressIndicator progress)
throws java.io.IOException
dest should not exist: with
the file system currently looking like
/
dir1/
a.txt
dir2/
Running recursiveCopy(new File("/dir1"), new File("/dir2"), fOp) will result in an
exception, while recursiveCopy(new File("/dir1"), new File("/dir2/foo") will result
in
/
dir1/
a.txt
dir2/
foo/
a.txt
This is equivalent to the behavior of cp -r when the target does not exist.src - File to copydest - Destination.fop - The FileOp to use for file operations.java.io.IOException - If the destination already exists, or if there is a problem copying the
files or creating directories.public static void safeRecursiveOverwrite(@NonNull
java.io.File src,
@NonNull
java.io.File dest,
@NonNull
FileOp fop,
@NonNull
ProgressIndicator progress)
throws java.io.IOException
src - File to movedest - Destination. Follows the same rules as recursiveCopy(File, File,
FileOp, ProgressIndicator)}.fop - The FileOp to use for file operations.progress - Currently only used for error logging.java.io.IOException - If some problem occurs during copies or directory creation.@Nullable
public static java.io.File getNewTempDir(@NonNull
java.lang.String base,
@NonNull
FileOp fileOp)
<base> + NN, where NN makes the directory distinct from any existing directories.@NonNull
public static java.io.File getTempDir(@NonNull
java.lang.String base,
int i)
@NonNull
public static java.io.File append(@NonNull
java.io.File base,
@NonNull
java.lang.String... segments)
segments to the base file.base - A base file, non-null.segments - Individual folder or filename segments to append to the base file.@NonNull
public static java.io.File append(@NonNull
java.lang.String base,
@NonNull
java.lang.String... segments)
segments to the base file.base - A base file path, non-empty and non-null.segments - Individual folder or filename segments to append to the base path.@NonNull
public static java.lang.String makeRelative(@NonNull
java.io.File baseDir,
@NonNull
java.io.File toBeRelative,
FileOp fop)
throws java.io.IOException
baseDir - The base directory to be relative to.toBeRelative - The file or directory to make relative to the base.fop - FileOp, in this case just to determine the platform.java.io.IOException - If drive letters don't match on Windows or path canonicalization fails.public static void retainTempDirs(java.util.Set<java.io.File> retain,
java.lang.String base,
FileOp mFop)
retain.