Class FileUtils
java.lang.Object
org.aksw.commons.io.util.FileUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPolicies for when the target file already exists -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longcopy(Path source, OutputStream out, IntConsumer contribCallback) static voidcopyDirectory(Path source, Path target, CopyOption... options) protected static voidcopyDirectoryInternal(Path source, Path target, CopyOption... options) voiddeleteDirectoryIfEmpty(Path path) Delete a path if it is an empty directorystatic voiddeleteEmptyFolders(Path path, Path baseFolder, boolean alsoDeleteBase) Delete parent folders of 'path' that are descendants of baseFolder (depending on the flag inclusive or exclusive)static booleandeleteFileIfExistsAndThenDeleteEmptyFolders(Path path, Path baseFolder, boolean alsoDeleteBaseFolder) Delete a specific path and then - regardless of deletion outcome -try to delete all empty directories up to a given baseFolder.static voiddeleteRecursivelyIfExists(Path path, com.google.common.io.RecursiveDeleteOption... options) static PathfindInAncestors(Path start, String fileName) Look for a file among all ancestor foldersstatic PathgetFirstExistingAncestor(Path path) Return the first ancestor of a path that exists.static FileTimeReturn a list of files matching a given glob pattern and a base pathstatic voidmoveAtomic(Path srcFile, Path tgtPath) Deprecated.static voidmoveAtomicIfSupported(Consumer<String> warnCallback, Path source, Path target) static OutputStreamnewOutputStream(OutputConfig config) Attempt to open an output stream to the given filestatic <T> TreadObject(Path target) static voidsafeCreate(Path target, Function<OutputStream, OutputStream> encoder, FileUtils.OverwritePolicy overwritePolicy, ThrowingConsumer<OutputStream> writer) static voidsafeCreate(Path target, FileUtils.OverwritePolicy overwritePolicy, ThrowingConsumer<OutputStream> writer) static longsizeOfDirectory(Path dirPath) A java.nio variant of apache commons-io FileUtils.sizeOfDirectory.static longsizeOfDirectory(Path dirPath, PathMatcher fileMatcher) A java.nio variant of apache commons-io FileUtils.sizeOfDirectory.static longtransferTo(OutputStream out, InputStream in, IntConsumer contribCallback) static voidwriteObject(Path target, Object obj) Most basic (and limited) serialization approach using ObjectOutputStream
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
newOutputStream
Attempt to open an output stream to the given file- Throws:
IOException
-
deleteRecursivelyIfExists
public static void deleteRecursivelyIfExists(Path path, com.google.common.io.RecursiveDeleteOption... options) throws IOException - Throws:
IOException
-
getFirstExistingAncestor
Return the first ancestor of a path that exists. May be the path itself or one if its transitive parents. Returns null on null input. UsePath.relativize(Path)to obtain the folders that would have to be created. -
deleteFileIfExistsAndThenDeleteEmptyFolders
public static boolean deleteFileIfExistsAndThenDeleteEmptyFolders(Path path, Path baseFolder, boolean alsoDeleteBaseFolder) throws IOException Delete a specific path and then - regardless of deletion outcome -try to delete all empty directories up to a given baseFolder. Empty folders are only deleted if their path starts with the baseFolder The result is the same as ofFiles.deleteIfExists(Path).- Throws:
IOException
-
deleteEmptyFolders
-
moveAtomic
-
moveAtomicIfSupported
public static void moveAtomicIfSupported(Consumer<String> warnCallback, Path source, Path target) throws IOException - Throws:
IOException
-
safeCreate
public static void safeCreate(Path target, FileUtils.OverwritePolicy overwritePolicy, ThrowingConsumer<OutputStream> writer) throws Exception - Throws:
Exception
-
getLastModifiedTimeOrNull
-
safeCreate
public static void safeCreate(Path target, Function<OutputStream, OutputStream> encoder, FileUtils.OverwritePolicy overwritePolicy, ThrowingConsumer<OutputStream> writer) throws Exception - Parameters:
target-encoder- A function that can wrap the OutputStream to the target file. May be null.overwritePolicy-writer- The action that writes to the (possibly encoded) output stream.- Throws:
Exception
-
deleteDirectoryIfEmpty
Delete a path if it is an empty directory- Throws:
IOException
-
listPaths
Return a list of files matching a given glob pattern and a base path- Parameters:
basePath-glob-- Returns:
- Throws:
IOException
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
writeObject
Most basic (and limited) serialization approach using ObjectOutputStream- Throws:
IOException
-
sizeOfDirectory
A java.nio variant of apache commons-io FileUtils.sizeOfDirectory.- Parameters:
dirPath-- Returns:
- Throws:
IOException
-
sizeOfDirectory
A java.nio variant of apache commons-io FileUtils.sizeOfDirectory.- Parameters:
dirPath-fileMatcher- Predicate to test whether to take a certain file's size into account for the total sum null will match any file.- Returns:
- Throws:
IOException
-
ancestors
-
ancestors
-
findInAncestors
-
copyDirectory
public static void copyDirectory(Path source, Path target, CopyOption... options) throws IOException - Throws:
IOException
-
copyDirectoryInternal
protected static void copyDirectoryInternal(Path source, Path target, CopyOption... options) throws IOException - Throws:
IOException
-
copy
public static long copy(Path source, OutputStream out, IntConsumer contribCallback) throws IOException - Throws:
IOException
-
transferTo
public static long transferTo(OutputStream out, InputStream in, IntConsumer contribCallback) throws IOException - Throws:
IOException
-