de.unkrig.commons.file.org.apache.commons.compress.compressors
Class CompressionFormatFactory

java.lang.Object
  extended by de.unkrig.commons.file.org.apache.commons.compress.compressors.CompressionFormatFactory

public abstract class CompressionFormatFactory
extends java.lang.Object

Manages CompressionFormats.

Additional compression formats can be 'plugged in' at runtime by putting a resource named FORMATS_RESOURCE on the classpath.


Method Summary
static java.util.Collection<CompressionFormat> allFormats()
           
static org.apache.commons.compress.compressors.CompressorInputStream compressorInputStream(java.io.InputStream inputStream)
          Determines the compression format from the first few bytes of the inputStream and then wraps it in the appropriate CompressorInputStream.
static CompressionFormat forCompressorOutputStream(org.apache.commons.compress.compressors.CompressorOutputStream compressorOutputStream)
          Deprecated. Should be replaced by a new method CompressorOutputStream.getFormat()
static CompressionFormat forContents(java.io.File file)
          Reads the first few bytes from the given file and determines the compression format.
static CompressionFormat forContents(java.io.InputStream is)
          Reads the first few bytes from the given input stream and determines the compression format.
static CompressionFormat forFileName(java.lang.String fileName)
           
static CompressionFormat forFormatName(java.lang.String compressionFormatName)
           
static long getUncompressedSize(org.apache.commons.compress.compressors.CompressorInputStream compressorInputStream)
          Deprecated. Should be replaced by a new method CompressorInputStream.getUncompressedSize()
static org.apache.commons.compress.compressors.CompressorInputStream open(java.io.File compressedFile)
          Determines the compression format from the first few bytes of the compressedFile and then returns a CompressorInputStream reading from the compressedFile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

allFormats

public static java.util.Collection<CompressionFormat> allFormats()
Returns:
A collection of all registered compression formats

forFileName

@Nullable
public static CompressionFormat forFileName(java.lang.String fileName)
Returns:
The CompressionFormat for the given file name, or null iff a compression format cannot be deduced from the fileName
See Also:
FileNameUtil.isCompressedFilename(String)

forFormatName

public static CompressionFormat forFormatName(java.lang.String compressionFormatName)
                                       throws org.apache.commons.compress.compressors.CompressorException
Returns:
The CompressionFormat for the given compressionFormatName
Throws:
org.apache.commons.compress.compressors.CompressorException - The compressionFormatName is unknown

forContents

@Nullable
public static CompressionFormat forContents(java.io.InputStream is)
                                     throws java.io.IOException
Reads the first few bytes from the given input stream and determines the compression format.

Returns:
One of allFormats(), or null iff the stream contents has none of the known compression formats
Throws:
java.io.IOException

forContents

@Nullable
public static CompressionFormat forContents(java.io.File file)
                                     throws java.io.IOException
Reads the first few bytes from the given file and determines the compression format.

Returns:
One of allFormats(), or null iff the file contents has none of the known compression formats
Throws:
java.io.IOException

forCompressorOutputStream

@Deprecated
public static CompressionFormat forCompressorOutputStream(org.apache.commons.compress.compressors.CompressorOutputStream compressorOutputStream)
Deprecated. Should be replaced by a new method CompressorOutputStream.getFormat()

Returns:
The compression format produced by the compressorOutputStream

getUncompressedSize

@Deprecated
public static long getUncompressedSize(org.apache.commons.compress.compressors.CompressorInputStream compressorInputStream)
Deprecated. Should be replaced by a new method CompressorInputStream.getUncompressedSize()

Returns:
The size of the uncompressed contents of the given compressor input stream, or -1L if unknown

compressorInputStream

public static org.apache.commons.compress.compressors.CompressorInputStream compressorInputStream(java.io.InputStream inputStream)
                                                                                           throws java.io.IOException,
                                                                                                  org.apache.commons.compress.compressors.CompressorException
Determines the compression format from the first few bytes of the inputStream and then wraps it in the appropriate CompressorInputStream.

Throws:
java.io.IOException
org.apache.commons.compress.compressors.CompressorException

open

public static org.apache.commons.compress.compressors.CompressorInputStream open(java.io.File compressedFile)
                                                                          throws java.io.IOException,
                                                                                 org.apache.commons.compress.compressors.CompressorException
Determines the compression format from the first few bytes of the compressedFile and then returns a CompressorInputStream reading from the compressedFile.

Is typically faster than CompressionFormatFactory.forContents(compressedFile).compressorInputStream(compressedFile).

Throws:
java.io.IOException
org.apache.commons.compress.compressors.CompressorException