de.unkrig.commons.file.org.apache.commons.compress.archivers
Class ArchiveFormatFactory

java.lang.Object
  extended by de.unkrig.commons.file.org.apache.commons.compress.archivers.ArchiveFormatFactory

public abstract class ArchiveFormatFactory
extends java.lang.Object

Manages ArchiveFormats.

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


Method Summary
static java.util.Collection<ArchiveFormat> allFormats()
           
static org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream(java.io.InputStream inputStream)
          Determines the archive format from the first few bytes of the inputStream and then wraps it in the appropriate ArchiveInputStream.
static ArchiveFormat forArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream archiveOutputStream)
          Deprecated. Should be replaced by a new method ArchiveOutputStream.getFormat()
static ArchiveFormat forContents(java.io.File file)
          Reads the first few bytes from the given file and determines the archive format.
static ArchiveFormat forContents(java.io.InputStream is)
          Reads the first few bytes from the given input stream and determines the archive format.
static ArchiveFormat forFileName(java.lang.String fileName)
           
static ArchiveFormat forFormatName(java.lang.String archiveFormatName)
           
static long getEntryCrc32(org.apache.commons.compress.archivers.ArchiveEntry archiveEntry)
          Deprecated. Should be replaced by a new method ArchiveEntry.getCrc32()
static org.apache.commons.compress.archivers.ArchiveInputStream open(java.io.File archiveFile)
          Determines the archive format from the first few bytes of the archiveFile and then returns a ArchiveInputStream reading from the archiveFile.
 
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<ArchiveFormat> allFormats()
Returns:
A collection of all registered archive formats

forFileName

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

forFormatName

public static ArchiveFormat forFormatName(java.lang.String archiveFormatName)
                                   throws org.apache.commons.compress.archivers.ArchiveException
Returns:
The ArchiveFormat for the given archiveFormatName
Throws:
org.apache.commons.compress.archivers.ArchiveException - The archiveFormatName is unknown

forContents

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

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

forContents

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

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

forArchiveOutputStream

@Deprecated
public static ArchiveFormat forArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream archiveOutputStream)
Deprecated. Should be replaced by a new method ArchiveOutputStream.getFormat()

Returns:
The ArchiveFormat corresponding with the archiveOutputStream

getEntryCrc32

@Deprecated
public static long getEntryCrc32(org.apache.commons.compress.archivers.ArchiveEntry archiveEntry)
Deprecated. Should be replaced by a new method ArchiveEntry.getCrc32()

Returns:
The CRC32 (0...0xffffffffL) of the contents of the given archive entry, or -1L if unknown

archiveInputStream

public static org.apache.commons.compress.archivers.ArchiveInputStream archiveInputStream(java.io.InputStream inputStream)
                                                                                   throws java.io.IOException,
                                                                                          org.apache.commons.compress.archivers.ArchiveException
Determines the archive format from the first few bytes of the inputStream and then wraps it in the appropriate ArchiveInputStream.

Throws:
java.io.IOException
org.apache.commons.compress.archivers.ArchiveException

open

public static org.apache.commons.compress.archivers.ArchiveInputStream open(java.io.File archiveFile)
                                                                     throws java.io.IOException,
                                                                            org.apache.commons.compress.archivers.ArchiveException
Determines the archive format from the first few bytes of the archiveFile and then returns a ArchiveInputStream reading from the archiveFile.

Is typically faster than ArchiveFormatFactory.forContents(archiveFile).archiveInputStream(archiveFile).

Throws:
java.io.IOException
org.apache.commons.compress.archivers.ArchiveException