public final class FileProcessings
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FileProcessings.DirectoryCombiner<T>
Transforms the return values of the invocations of
directoryMemberProcessor for each member. |
| Modifier and Type | Method and Description |
|---|---|
static <T> FileProcessor<T> |
archiveCompressedAndNormalFileProcessor(Predicate<? super java.lang.String> lookIntoFormat,
ContentsProcessor<T> archiveContentsProcessor,
ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
ContentsProcessor<T> compressedContentsProcessor,
ContentsProcessor<T> normalContentsProcessor,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a
FileProcessor which processes files by feeding their contents either to the archiveContentsProcessor, the compressedContentsProcessor or the normalContentsProcessor}. |
static <T> FileProcessor<T> |
directoryProcessor(Predicate<? super java.lang.String> pathPredicate,
FileProcessor<T> regularFileProcessor,
java.util.Comparator<java.lang.Object> directoryMemberNameComparator,
FileProcessor<T> directoryMemberProcessor,
FileProcessings.DirectoryCombiner<T> directoryCombiner,
SquadExecutor<T> squadExecutor,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a
FileProcessor which processes directories and regular files. |
static <T> FileProcessor<T> |
directoryTreeProcessor(Predicate<? super java.lang.String> pathPredicate,
FileProcessor<T> regularFileProcessor,
java.util.Comparator<java.lang.Object> directoryMemberNameComparator,
FileProcessings.DirectoryCombiner<T> directoryCombiner,
SquadExecutor<T> squadExecutor,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a
FileProcessor which processes directories and regular files exactly like the FileProcessor returned by directoryProcessor(Predicate, FileProcessor, Comparator, FileProcessor,
DirectoryCombiner, SquadExecutor, ExceptionHandler), except that it processes directory members
recursively. |
static <T> FileProcessor<T> |
nop() |
static <T> FileProcessings.DirectoryCombiner<T> |
nopDirectoryCombiner()
A
FileProcessings.DirectoryCombiner which ignores the combinables and returns null. |
static <T> void |
process(java.util.List<java.io.File> files,
FileProcessor<T> fileProcessor) |
static <T> void |
process(java.util.List<java.io.File> files,
FileProcessor<T> fileProcessor,
ExceptionHandler<java.io.IOException> exceptionHandler)
Invokes the
fileProcessor for each of the files. |
static <T> FileProcessor<T> |
recursiveCompressedAndArchiveFileProcessor(Predicate<? super java.lang.String> lookIntoFormat,
ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
ContentsProcessor<T> delegate,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a
FileProcessor which processes files by feeding their contents through the delegate
(just like the FileContentsProcessor), but automagically detects various archive and compression formats
(also nested) and processes the entries of the archive and the uncompressed contents instead of
the "raw" contents. |
public static <T> FileProcessor<T> nop()
FileProcessor that does nothing and returns null.public static <T> void process(java.util.List<java.io.File> files,
FileProcessor<T> fileProcessor)
throws java.io.IOException,
java.lang.InterruptedException
java.io.IOExceptionjava.lang.InterruptedExceptionprocess(List, FileProcessor, ExceptionHandler)public static <T> void process(java.util.List<java.io.File> files,
FileProcessor<T> fileProcessor,
ExceptionHandler<java.io.IOException> exceptionHandler)
throws java.io.IOException,
java.lang.InterruptedException
fileProcessor for each of the files.exceptionHandler - Called if the processing of one of the inputFiles throws an IOException
or a RuntimeExceptionjava.io.IOExceptionjava.lang.InterruptedExceptionpublic static <T> FileProcessor<T> directoryTreeProcessor(Predicate<? super java.lang.String> pathPredicate, FileProcessor<T> regularFileProcessor, @Nullable java.util.Comparator<java.lang.Object> directoryMemberNameComparator, FileProcessings.DirectoryCombiner<T> directoryCombiner, SquadExecutor<T> squadExecutor, ExceptionHandler<java.io.IOException> exceptionHandler)
FileProcessor which processes directories and regular files exactly like the FileProcessor returned by directoryProcessor(Predicate, FileProcessor, Comparator, FileProcessor,
DirectoryCombiner, SquadExecutor, ExceptionHandler), except that it processes directory members
recursively.
Notice that the list passed to the directoryCombiner can contain null values iff the
regularFileProcessor returns null values.
directoryMemberNameComparator - The comparator used to sort a directory's members; a null value
means to NOT sort the members, i.e. leave them in their 'natural' order as
File.list() returns themdirectoryProcessor(Predicate, FileProcessor, Comparator, FileProcessor,
DirectoryCombiner, SquadExecutor, ExceptionHandler)public static <T> FileProcessor<T> directoryProcessor(Predicate<? super java.lang.String> pathPredicate, FileProcessor<T> regularFileProcessor, @Nullable java.util.Comparator<java.lang.Object> directoryMemberNameComparator, FileProcessor<T> directoryMemberProcessor, FileProcessings.DirectoryCombiner<T> directoryCombiner, SquadExecutor<T> squadExecutor, ExceptionHandler<java.io.IOException> exceptionHandler)
FileProcessor which processes directories and regular files.
Its behavior is as follows:
regularFileProcessor is invoked and its result is
returned.
pathPredicate, the directory can impossibly contain relevant documents,
null is returned.
directoryMemberNameComparator is not null, the members are sorted according to
the directoryMemberNameComparator
directoryMemberProcessor is invoked for each member, and the return values are stored in a
list.
directoryCombiner is invoked with that list. (Notice that the list may contain null
values iff the directoryMemberProcessor returns null values.)
directoryCombiner is returned.
pathPredicate is only used to avoid unnecessary directory scans; apart from that the
regularFileProcessor and the directoryMemberProcessor are called for any file without
further ado.
If you use Void for <T>, then nopDirectoryCombiner() is the right directoryCombiner.
T - The return type of all FileProcessor.process(String, File) methodssquadExecutor - Is used to process independent subtrees - could be ConcurrentUtil.SEQUENTIAL_EXECUTOR_SERVICEdirectoryMemberNameComparator - The comparator used to sort a directory's members; a null value
means to NOT sort the members, i.e. leave them in their 'natural' order as
File.list() returns thempublic static <T> FileProcessings.DirectoryCombiner<T> nopDirectoryCombiner()
FileProcessings.DirectoryCombiner which ignores the combinables and returns null.public static <T> FileProcessor<T> archiveCompressedAndNormalFileProcessor(Predicate<? super java.lang.String> lookIntoFormat, ContentsProcessor<T> archiveContentsProcessor, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> compressedContentsProcessor, ContentsProcessor<T> normalContentsProcessor, ExceptionHandler<java.io.IOException> exceptionHandler)
FileProcessor which processes files by feeding their contents either to the archiveContentsProcessor, the compressedContentsProcessor or the normalContentsProcessor}.
Archive files and compressed files are introspected iff lookIntoFormat evaluates true for
"format:path".
lookIntoFormat - See CompressUtil.processFile(String, File, Predicate, ArchiveHandler,
CompressorHandler, NormalContentsHandler)public static <T> FileProcessor<T> recursiveCompressedAndArchiveFileProcessor(Predicate<? super java.lang.String> lookIntoFormat, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> delegate, ExceptionHandler<java.io.IOException> exceptionHandler)
FileProcessor which processes files by feeding their contents through the delegate
(just like the FileContentsProcessor), but automagically detects various archive and compression formats
(also nested) and processes the entries of the archive and the uncompressed contents instead of
the "raw" contents.
Archive files/entries and compressed files/entries are introspected iff lookIntoFormat evaluates true for "format:path".