de.unkrig.commons.file.contentstransformation
Class ContentsTransformations

java.lang.Object
  extended by de.unkrig.commons.file.contentstransformation.ContentsTransformations

public final class ContentsTransformations
extends java.lang.Object

Utility class for ContentsTransformer.


Field Summary
static ContentsTransformer COPY
          A ContentsTransformer which IoUtil.copy(InputStream, OutputStream)s all data unmodified and returns the number of copied bytes.
 
Method Summary
static CompressUtil.ArchiveHandler<java.lang.Void> archiveHandler(java.lang.String path, java.io.OutputStream os, Predicate<java.lang.String> archiveEntryRemoval, Glob archiveEntryRenaming, ContentsTransformer contentsTransformer, FileTransformations.ArchiveCombiner archiveFileCombiner, ExceptionHandler<java.io.IOException> exceptionHandler)
          Creates and returns an CompressUtil.ArchiveHandler which transforms ArchiveInputStreams into ArchiveOutputStreams, honoring the given archiveEntryRemoval, archiveEntryRenaming and archiveEntryAddition, and using the given contentsTransformer.
static ContentsTransformer compressedAndArchiveContentsTransformer(Predicate<java.lang.String> lookIntoFormat, Predicate<java.lang.String> archiveEntryRemoval, Glob archiveEntryRenaming, ContentsTransformer archiveEntryContentsTransformer, FileTransformations.ArchiveCombiner archiveCombiner, ContentsTransformer compressedContentsTransformer, ContentsTransformer normalContentsTransformer, ExceptionHandler<java.io.IOException> exceptionHandler)
          Returns a ContentsTransformer which transforms contents by feeding it through the normalContentsTransformer, but automagically detects various archive and compression formats and processes the entries of the archive and the uncompressed contents instead of the "raw" contents.
static CompressUtil.CompressorHandler<java.lang.Void> compressorHandler(java.lang.String path, java.io.OutputStream os, ContentsTransformer contentsTransformer)
          Creates and returns a CompressUtil.CompressorHandler which transforms an ArchiveInputStream into an OutputStream, using the given contentsTransformer.
static CompressUtil.NormalContentsHandler<java.lang.Void> normalContentsHandler(java.lang.String path, java.io.OutputStream os, ContentsTransformer contentsTransformer)
          Creates and returns a handler which transforms an InputStream into an OutputStream using the given contentsTransformer.
static ContentsTransformer recursiveCompressedAndArchiveContentsTransformer(Predicate<java.lang.String> lookIntoFormat, Predicate<java.lang.String> archiveEntryRemoval, Glob archiveEntryRenaming, FileTransformations.ArchiveCombiner archiveCombiner, ContentsTransformer delegate, ExceptionHandler<java.io.IOException> exceptionHandler)
          Returns a ContentsTransformer which transforms a stream by feeding it through the delegate, but automagically detects various archive formats and compression formats (also nested) and processes the entries of the archive and the uncompressed contents instead of the "raw" contents.
static void transformArchive(java.lang.String path, org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream, org.apache.commons.compress.archivers.ArchiveOutputStream archiveOutputStream, Predicate<java.lang.String> archiveEntryRemoval, Glob archiveEntryRenaming, ContentsTransformer contentsTransformer, FileTransformations.ArchiveCombiner archiveCombiner, ExceptionHandler<java.io.IOException> exceptionHandler)
          Transforms the given archiveInputStream into the given archiveOutputStream, honoring the given archiveEntryRemoval, archiveEntryRenaming and archiveEntryAddition, and using the given contentsTransformer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPY

public static final ContentsTransformer COPY
A ContentsTransformer which IoUtil.copy(InputStream, OutputStream)s all data unmodified and returns the number of copied bytes.

Method Detail

compressedAndArchiveContentsTransformer

public static ContentsTransformer compressedAndArchiveContentsTransformer(Predicate<java.lang.String> lookIntoFormat,
                                                                          Predicate<java.lang.String> archiveEntryRemoval,
                                                                          Glob archiveEntryRenaming,
                                                                          ContentsTransformer archiveEntryContentsTransformer,
                                                                          FileTransformations.ArchiveCombiner archiveCombiner,
                                                                          ContentsTransformer compressedContentsTransformer,
                                                                          ContentsTransformer normalContentsTransformer,
                                                                          ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a ContentsTransformer which transforms contents by feeding it through the normalContentsTransformer, but automagically detects various archive and compression formats and processes the entries of the archive and the uncompressed contents instead of the "raw" contents.

Archive files and compressed files are introspected iff lookIntoFormat evaluates true for "format:path".


recursiveCompressedAndArchiveContentsTransformer

public static ContentsTransformer recursiveCompressedAndArchiveContentsTransformer(Predicate<java.lang.String> lookIntoFormat,
                                                                                   Predicate<java.lang.String> archiveEntryRemoval,
                                                                                   Glob archiveEntryRenaming,
                                                                                   FileTransformations.ArchiveCombiner archiveCombiner,
                                                                                   ContentsTransformer delegate,
                                                                                   ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a ContentsTransformer which transforms a stream by feeding it through the delegate, but automagically detects various archive formats and compression formats (also nested) and processes the entries of the archive and the uncompressed contents instead of the "raw" contents.

Archive streams/entries and compressed streams/entries are introspected iff lookIntoFormat evaluates true for "format:path".


transformArchive

public static void transformArchive(java.lang.String path,
                                    org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream,
                                    org.apache.commons.compress.archivers.ArchiveOutputStream archiveOutputStream,
                                    Predicate<java.lang.String> archiveEntryRemoval,
                                    Glob archiveEntryRenaming,
                                    ContentsTransformer contentsTransformer,
                                    FileTransformations.ArchiveCombiner archiveCombiner,
                                    ExceptionHandler<java.io.IOException> exceptionHandler)
                             throws java.io.IOException
Transforms the given archiveInputStream into the given archiveOutputStream, honoring the given archiveEntryRemoval, archiveEntryRenaming and archiveEntryAddition, and using the given contentsTransformer.

Throws:
java.io.IOException

archiveHandler

public static CompressUtil.ArchiveHandler<java.lang.Void> archiveHandler(java.lang.String path,
                                                                         java.io.OutputStream os,
                                                                         Predicate<java.lang.String> archiveEntryRemoval,
                                                                         Glob archiveEntryRenaming,
                                                                         ContentsTransformer contentsTransformer,
                                                                         FileTransformations.ArchiveCombiner archiveFileCombiner,
                                                                         ExceptionHandler<java.io.IOException> exceptionHandler)
Creates and returns an CompressUtil.ArchiveHandler which transforms ArchiveInputStreams into ArchiveOutputStreams, honoring the given archiveEntryRemoval, archiveEntryRenaming and archiveEntryAddition, and using the given contentsTransformer.


compressorHandler

public static CompressUtil.CompressorHandler<java.lang.Void> compressorHandler(java.lang.String path,
                                                                               java.io.OutputStream os,
                                                                               ContentsTransformer contentsTransformer)
Creates and returns a CompressUtil.CompressorHandler which transforms an ArchiveInputStream into an OutputStream, using the given contentsTransformer.


normalContentsHandler

public static CompressUtil.NormalContentsHandler<java.lang.Void> normalContentsHandler(java.lang.String path,
                                                                                       java.io.OutputStream os,
                                                                                       ContentsTransformer contentsTransformer)
Creates and returns a handler which transforms an InputStream into an OutputStream using the given contentsTransformer.