de.unkrig.commons.file.contentsprocessing
Class ContentsProcessings

java.lang.Object
  extended by de.unkrig.commons.file.contentsprocessing.ContentsProcessings

public final class ContentsProcessings
extends java.lang.Object

ContentsProcessor-related utility methods.


Nested Class Summary
static interface ContentsProcessings.ArchiveCombiner<T>
          Combines the results of ContentsProcessor.process(String, InputStream, long, long, ProducerWhichThrows) for all archive entries into one object.
 
Method Summary
static
<T> CompressUtil.ArchiveHandler<T>
archiveHandler(java.lang.String path, ContentsProcessor<T> contentsProcessor, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener, ExceptionHandler<java.io.IOException> exceptionHandler)
          Creates and returns an CompressUtil.ArchiveHandler which processes ArchiveInputStreams by feeding their entries into the contentsProcessor.
static
<T> ContentsProcessor<T>
compressedAndArchiveContentsProcessor(Predicate<java.lang.String> lookIntoFormat, ContentsProcessor<T> archiveContentsProcessor, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> compressedContentsProcessor, ContentsProcessor<T> normalContentsProcessor, ExceptionHandler<java.io.IOException> exceptionHandler)
          Returns a ContentsProcessor which processes contents by feeding it to the normalContentsProcessor, 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
<T> CompressUtil.CompressorHandler<T>
compressorHandler(java.lang.String path, ContentsProcessor<T> contentsProcessor, ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener)
          Creates and returns a CompressUtil.CompressorHandler which processes an ArchiveInputStream by feeding its entries to the given contentsProcessor.
static
<T> ContentsProcessings.ArchiveCombiner<T>
nopArchiveCombiner()
           
static
<T> ContentsProcessor<T>
nopContentsProcessor()
           
static
<T> CompressUtil.NormalContentsHandler<T>
normalContentsHandler(java.lang.String path, ContentsProcessor<T> contentsProcessor, long size, long crc32, ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener)
          Creates and returns a TransformerWhichThrows which processes an InputStream by feeding it into the given contentsProcessor.
static
<T> T
processArchive(java.lang.String archivePath, org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream, ContentsProcessor<T> contentsProcessor, ContentsProcessings.ArchiveCombiner<T> entryCombiner, ProducerWhichThrows<org.apache.commons.compress.archivers.ArchiveInputStream,java.io.IOException> archiveOpener, ExceptionHandler<java.io.IOException> exceptionHandler)
          Process the given archiveInputStream by feeding the contents of each archive entry through the given contentsProcessor.
static
<T> ContentsProcessor<T>
recursiveCompressedAndArchiveContentsProcessor(Predicate<java.lang.String> lookIntoFormat, ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner, ContentsProcessor<T> normalContentsProcessor, ExceptionHandler<java.io.IOException> exceptionHandler)
          Returns a ContentsProcessor which processes a stream by feeding it into the normalContentsProcessor, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

nopContentsProcessor

public static <T> ContentsProcessor<T> nopContentsProcessor()
Returns:
A ContentsProcessor that does not read any of the contents.

nopArchiveCombiner

public static <T> ContentsProcessings.ArchiveCombiner<T> nopArchiveCombiner()
Returns:
An ContentsProcessings.ArchiveCombiner which always returns null

processArchive

@Nullable
public static <T> T processArchive(java.lang.String archivePath,
                                            org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream,
                                            ContentsProcessor<T> contentsProcessor,
                                            ContentsProcessings.ArchiveCombiner<T> entryCombiner,
                                            ProducerWhichThrows<org.apache.commons.compress.archivers.ArchiveInputStream,java.io.IOException> archiveOpener,
                                            ExceptionHandler<java.io.IOException> exceptionHandler)
                        throws java.io.IOException
Process the given archiveInputStream by feeding the contents of each archive entry through the given contentsProcessor.

Parameters:
exceptionHandler - Invoked if the contentsProcessor throws an exception; if it completes normally, then processing continues with the next archive entry
Throws:
java.io.IOException

compressedAndArchiveContentsProcessor

public static <T> ContentsProcessor<T> compressedAndArchiveContentsProcessor(Predicate<java.lang.String> lookIntoFormat,
                                                                             ContentsProcessor<T> archiveContentsProcessor,
                                                                             ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
                                                                             ContentsProcessor<T> compressedContentsProcessor,
                                                                             ContentsProcessor<T> normalContentsProcessor,
                                                                             ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a ContentsProcessor which processes contents by feeding it to the normalContentsProcessor, 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".


recursiveCompressedAndArchiveContentsProcessor

public static <T> ContentsProcessor<T> recursiveCompressedAndArchiveContentsProcessor(Predicate<java.lang.String> lookIntoFormat,
                                                                                      ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
                                                                                      ContentsProcessor<T> normalContentsProcessor,
                                                                                      ExceptionHandler<java.io.IOException> exceptionHandler)
Returns a ContentsProcessor which processes a stream by feeding it into the normalContentsProcessor, 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".


archiveHandler

public static <T> CompressUtil.ArchiveHandler<T> archiveHandler(java.lang.String path,
                                                                ContentsProcessor<T> contentsProcessor,
                                                                ContentsProcessings.ArchiveCombiner<T> archiveEntryCombiner,
                                                                ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener,
                                                                ExceptionHandler<java.io.IOException> exceptionHandler)
Creates and returns an CompressUtil.ArchiveHandler which processes ArchiveInputStreams by feeding their entries into the contentsProcessor.

Parameters:
opener - TODO

compressorHandler

public static <T> CompressUtil.CompressorHandler<T> compressorHandler(java.lang.String path,
                                                                      ContentsProcessor<T> contentsProcessor,
                                                                      ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener)
Creates and returns a CompressUtil.CompressorHandler which processes an ArchiveInputStream by feeding its entries to the given contentsProcessor.

Parameters:
opener - Re-produces the input stream

normalContentsHandler

public static <T> CompressUtil.NormalContentsHandler<T> normalContentsHandler(java.lang.String path,
                                                                              ContentsProcessor<T> contentsProcessor,
                                                                              long size,
                                                                              long crc32,
                                                                              ProducerWhichThrows<java.io.InputStream,java.io.IOException> opener)
Creates and returns a TransformerWhichThrows which processes an InputStream by feeding it into the given contentsProcessor.

Parameters:
size - -1 if unknown
crc32 - TODO
opener - Re-produces the