|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.file.filetransformation.FileTransformations
public final class FileTransformations
Various FileTransformer-related utility methods.
A typical application is to wrap file transformers and content transformers as follows:
|
v
directoryTreeTransformer()
|
v
recursiveCompressedAndArchiveFileTransformer()
|
v
(some contents fransformer, e.g. 'ContentsTransformerUtil.NOP')
The directoryTreeTransformer()) can be left out if you don't need recursive directory
traversal.
The recursiveCompressedAndArchiveFileTransformer() can be left out if
you don't want to look into archive /
compressed files.
| Nested Class Summary | |
|---|---|
static interface |
FileTransformations.ArchiveCombiner
|
static interface |
FileTransformations.DirectoryCombiner
|
static interface |
FileTransformations.NameAndContents
|
| Method Summary | |
|---|---|
static FileTransformer |
compressedAndArchiveFileTransformer(Predicate<java.lang.String> lookIntoFormat,
Predicate<java.lang.String> archiveEntryRemoval,
Glob archiveEntryRenaming,
FileTransformations.ArchiveCombiner archiveCombiner,
ContentsTransformer archiveEntryContentsTransformer,
ContentsTransformer compressedContentsTransformer,
ContentsTransformer normalContentsTransformer,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a FileTransformer which transforms files by feeding their contents through the normalContentsTransformer (just like the FileContentsTransformer), or, iff the file is an archive
file, by feeding the archive file's entries through the archiveEntryContentsTransformer, or, iff the
file is a compressed file, be feeding the compressed file's decompressed contents through the compressedContentsTransformer. |
static DirectoryTransformer |
directoryTreeTransformer(java.util.Comparator<java.lang.Object> directoryMemberNameComparator,
Predicate<java.lang.String> directoryMemberRemoval,
Glob directoryMemberRenaming,
FileTransformations.DirectoryCombiner directoryCombiner,
FileTransformer regularFileTransformer,
boolean saveSpace,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
Creates and returns a DirectoryTransformer which implements the following features:
Recursive processing of directories
Removal, renaming and addition of directory members
|
static java.io.File |
newFile(java.io.File file)
|
static java.io.File |
origFile(java.io.File file)
|
static FileTransformer |
recursiveCompressedAndArchiveFileTransformer(Predicate<java.lang.String> lookIntoFormat,
Predicate<java.lang.String> archiveEntryRemoval,
Glob archiveEntryRenaming,
FileTransformations.ArchiveCombiner archiveCombiner,
ContentsTransformer delegate,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a FileTransformer which transforms files by feeding their contents through the delegate
(just like the FileContentsTransformer), 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. |
static FileTransformer |
remove()
If in equals out ("in-place transformation"), then file in is deleted. |
static FileTransformer |
renameRemoveFileTransformer(Predicate<java.lang.String> removal,
Glob renaming,
FileTransformer delegate,
boolean saveSpace,
boolean keepOriginals)
|
static void |
transform(java.lang.String[] args,
FileTransformer fileTransformer,
FileTransformer.Mode mode,
ExceptionHandler<java.io.IOException> exceptionHandler)
Transforms a set of files based on an array of strings, similar to many UNIX™ command line tools. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static FileTransformer remove()
in equals out ("in-place transformation"), then file in is deleted. Otherwise
("out-of-place transformation") nothing is done, i.e. a file out is not created.
public static DirectoryTransformer directoryTreeTransformer(@Nullable
java.util.Comparator<java.lang.Object> directoryMemberNameComparator,
Predicate<java.lang.String> directoryMemberRemoval,
Glob directoryMemberRenaming,
FileTransformations.DirectoryCombiner directoryCombiner,
FileTransformer regularFileTransformer,
boolean saveSpace,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
DirectoryTransformer which implements the following features:
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 themdirectoryMemberRemoval - Whether to remove (i.e. not copy) a member; the subject is the path of the
memberdirectoryMemberRenaming - Transforms the name of a membersaveSpace - If true, then the method attempts to save file system space for
in-place transformations by transforming each file, otherwise it
creates a copy of the entire directory tree before deleting the original
public static FileTransformer renameRemoveFileTransformer(Predicate<java.lang.String> removal,
Glob renaming,
FileTransformer delegate,
boolean saveSpace,
boolean keepOriginals)
public static FileTransformer compressedAndArchiveFileTransformer(Predicate<java.lang.String> lookIntoFormat,
Predicate<java.lang.String> archiveEntryRemoval,
Glob archiveEntryRenaming,
FileTransformations.ArchiveCombiner archiveCombiner,
ContentsTransformer archiveEntryContentsTransformer,
ContentsTransformer compressedContentsTransformer,
ContentsTransformer normalContentsTransformer,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
FileTransformer which transforms files by feeding their contents through the normalContentsTransformer (just like the FileContentsTransformer), or, iff the file is an archive
file, by feeding the archive file's entries through the archiveEntryContentsTransformer, or, iff the
file is a compressed file, be feeding the compressed file's decompressed contents through the compressedContentsTransformer.
Archive files and compressed files are introspected iff lookIntoFormat evaluates true for
"format:path".
public static FileTransformer recursiveCompressedAndArchiveFileTransformer(Predicate<java.lang.String> lookIntoFormat,
Predicate<java.lang.String> archiveEntryRemoval,
Glob archiveEntryRenaming,
FileTransformations.ArchiveCombiner archiveCombiner,
ContentsTransformer delegate,
boolean keepOriginals,
ExceptionHandler<java.io.IOException> exceptionHandler)
FileTransformer which transforms files by feeding their contents through the delegate
(just like the FileContentsTransformer), 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.
lookIntoFormat - Whether the file/entry should be introspected; the subject is
"format:container-path"archiveEntryRemoval - Whether to remove (i.e. not copy) a subject file or an archive entry; the subject is
the path of the subject file resp. the archive entryarchiveEntryRenaming - Transforms the name of a subject file or an archive
entryarchiveCombiner - Is invoked after the processing of each archive
public static void transform(java.lang.String[] args,
FileTransformer fileTransformer,
FileTransformer.Mode mode,
ExceptionHandler<java.io.IOException> exceptionHandler)
throws java.io.IOException
If args.length == 1, then the file or directory args[0] is transformed in-place.
If args.length == 2 and args[1] is not an existing directory, then the file args[0] is
transformed into the file args[1].
If args.length >= 2 and args[args.length - 1] is an existing directory, then the files args[0] ... args[args.length - 2] are transformed into files with the same names in the directory
args[args.length - 1].
exceptionHandler - If the transformation of one of the inputFiles throws an IOException or
a RuntimeException, then ExceptionHandler.handle(Exception) resp. ExceptionHandler.handle(RuntimeException) is called. Iff that call completes normally,
then processing continues with the next inputFile.
java.io.IOException - args.length == 0
java.io.IOException - args.length > 2 and args[args.length - 1] is not an existing directorypublic static java.io.File newFile(java.io.File file)
file which is typically used to create a temporary file which is later
renamed to replace some 'original' filepublic static java.io.File origFile(java.io.File file)
file which is typically used as a container to keep an 'original' file
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||