Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.compress.archivers
Class ArchiveStreamFactory

    java.lang.Object
      org.apache.commons.compress.archivers.ArchiveStreamFactory

    public class ArchiveStreamFactory

extends Object

Factory to create Archive[In|Out]putStreams from names or the first bytes of the InputStream. In order add other implementations you should extend ArchiveStreamFactory and override the appropriate methods (and call their implementation from super of course).

Compressing a ZIP-File:

     final OutputStream out = new FileOutputStream(output);
     ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);

     os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
     IOUtils.copy(new FileInputStream(file1), os);
     os.closeArchiveEntry();

     os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml"));
     IOUtils.copy(new FileInputStream(file2), os);
     os.closeArchiveEntry();
     os.close();

Decompressing a ZIP-File:

     final InputStream is = new FileInputStream(input);
     ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
     ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry();
     OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
     IOUtils.copy(in, out);
     out.close();
     in.close();

This class is immutable

Field Summary
`static String` | `AR` Constant used to identify the AR archive format.
`static String` | `CPIO` Constant used to identify the CPIO archive format.
`static String` | `DUMP` Constant used to identify the Unix DUMP archive format.
`static String` | `JAR` Constant used to identify the JAR archive format.
`static String` | `TAR` Constant used to identify the TAR archive format.
`static String` | `ZIP` Constant used to identify the ZIP archive format.

Constructor Summary
`ArchiveStreamFactory()`

Method Summary
`ArchiveInputStream` | `createArchiveInputStream(InputStream in)` Create an archive input stream from an input stream, autodetecting the archive type from the first few bytes of the stream.
`ArchiveInputStream` | `createArchiveInputStream(String archiverName, InputStream in)` Create an archive input stream from an archiver name and an input stream.
`ArchiveOutputStream` | `createArchiveOutputStream(String archiverName, OutputStream out)` Create an archive output stream from an archiver name and an input stream.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### AR

    public static final String AR

  Constant used to identify the AR archive format.

  Since:
    Commons Compress 1.1
  See Also:
    Constant Field Values

### CPIO

    public static final String CPIO

  Constant used to identify the CPIO archive format.

  Since:
    Commons Compress 1.1
  See Also:
    Constant Field Values

### DUMP

    public static final String DUMP

  Constant used to identify the Unix DUMP archive format.

  Since:
    Commons Compress 1.3
  See Also:
    Constant Field Values

### JAR

    public static final String JAR

  Constant used to identify the JAR archive format.

  Since:
    Commons Compress 1.1
  See Also:
    Constant Field Values

### TAR

    public static final String TAR

  Constant used to identify the TAR archive format.

  Since:
    Commons Compress 1.1
  See Also:
    Constant Field Values

### ZIP

    public static final String ZIP

  Constant used to identify the ZIP archive format.

  Since:
    Commons Compress 1.1
  See Also:
    Constant Field Values

Constructor Detail

### ArchiveStreamFactory

    public ArchiveStreamFactory()

Method Detail

### createArchiveInputStream

    public ArchiveInputStream createArchiveInputStream(String archiverName,
                                                       InputStream in)
                                                throws ArchiveException

  Create an archive input stream from an archiver name and an input stream.

  Parameters:
    `archiverName` - the archive name, i.e. "ar", "zip", "tar", "jar", "dump" or "cpio"
    `in` - the input stream
  Returns:
    the archive input stream
  Throws:
    `ArchiveException` - if the archiver name is not known
    `IllegalArgumentException` - if the archiver name or stream is null

### createArchiveOutputStream

    public ArchiveOutputStream createArchiveOutputStream(String archiverName,
                                                         OutputStream out)
                                                  throws ArchiveException

  Create an archive output stream from an archiver name and an input stream.

  Parameters:
    `archiverName` - the archive name, i.e. "ar", "zip", "tar", "jar" or "cpio"
    `out` - the output stream
  Returns:
    the archive output stream
  Throws:
    `ArchiveException` - if the archiver name is not known
    `IllegalArgumentException` - if the archiver name or stream is null

### createArchiveInputStream

    public ArchiveInputStream createArchiveInputStream(InputStream in)
                                                throws ArchiveException

  Create an archive input stream from an input stream, autodetecting the archive type from the first few bytes of the stream. The InputStream must support marks, like BufferedInputStream.

  Parameters:
    `in` - the input stream
  Returns:
    the archive input stream
  Throws:
    `ArchiveException` - if the archiver name is not known
    `IllegalArgumentException` - if the stream is null or does not support mark

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 The Apache Software Foundation. All Rights Reserved.