public final class FileProcessings extends 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 String> lookIntoFormat,
ContentsProcessor<T> archiveContentsProcessor,
ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
ContentsProcessor<T> compressedContentsProcessor,
ContentsProcessor<T> normalContentsProcessor,
ExceptionHandler<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 String> pathPredicate,
FileProcessor<T> regularFileProcessor,
Comparator<Object> directoryMemberNameComparator,
FileProcessor<T> directoryMemberProcessor,
FileProcessings.DirectoryCombiner<T> directoryCombiner,
SquadExecutor<T> squadExecutor,
ExceptionHandler<IOException> exceptionHandler)
Returns a
FileProcessor which processes directories and regular files. |
static <T> FileProcessor<T> |
directoryTreeProcessor(Predicate<? super String> pathPredicate,
FileProcessor<T> regularFileProcessor,
Comparator<Object> directoryMemberNameComparator,
FileProcessings.DirectoryCombiner<T> directoryCombiner,
SquadExecutor<T> squadExecutor,
ExceptionHandler<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(List<File> files,
FileProcessor<T> fileProcessor) |
static <T> void |
process(List<File> files,
FileProcessor<T> fileProcessor,
ExceptionHandler<IOException> exceptionHandler)
Invokes the fileProcessor for each of the files.
|
static <T> FileProcessor<T> |
recursiveCompressedAndArchiveFileProcessor(Predicate<? super String> lookIntoFormat,
Predicate<? super String> pathPredicate,
ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
ContentsProcessor<T> delegate,
ExceptionHandler<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(List<File> files, FileProcessor<T> fileProcessor) throws IOException, InterruptedException
IOException
InterruptedException
process(List, FileProcessor, ExceptionHandler)
public static <T> void process(List<File> files, FileProcessor<T> fileProcessor, ExceptionHandler<IOException> exceptionHandler) throws IOException, InterruptedException
exceptionHandler
- Called if the processing of one of the files throws an IOException
or a RuntimeException
IOException
InterruptedException
public static <T> FileProcessor<T> directoryTreeProcessor(Predicate<? super String> pathPredicate, FileProcessor<T> regularFileProcessor, @Nullable Comparator<Object> directoryMemberNameComparator, FileProcessings.DirectoryCombiner<T> directoryCombiner, SquadExecutor<T> squadExecutor, ExceptionHandler<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 String> pathPredicate, FileProcessor<T> regularFileProcessor, @Nullable Comparator<Object> directoryMemberNameComparator, FileProcessor<T> directoryMemberProcessor, FileProcessings.DirectoryCombiner<T> directoryCombiner, SquadExecutor<T> squadExecutor, ExceptionHandler<IOException> exceptionHandler)
FileProcessor
which processes directories and regular files.
Its behavior is as follows:
null
is returned.
null
, the members are sorted according
to the directoryMemberNameComparator
null
values iff the directoryMemberProcessor returns null
values.)
Notice that the 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_SERVICE
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 thempublic static <T> FileProcessings.DirectoryCombiner<T> nopDirectoryCombiner()
FileProcessings.DirectoryCombiner
which ignores the combinables and returns null
.public static <T> FileProcessor<T> archiveCompressedAndNormalFileProcessor(Predicate<? super String> lookIntoFormat, ContentsProcessor<T> archiveContentsProcessor, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> compressedContentsProcessor, ContentsProcessor<T> normalContentsProcessor, ExceptionHandler<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 String> lookIntoFormat, Predicate<? super String> pathPredicate, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> delegate, ExceptionHandler<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".
Copyright © 2018 Arno Unkrig. All rights reserved.