public class ArchiveStreamFactory
extends java.lang.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();
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AR
Constant used to identify the AR archive format.
|
static java.lang.String |
CPIO
Constant used to identify the CPIO archive format.
|
static java.lang.String |
JAR
Constant used to identify the JAR archive format.
|
static java.lang.String |
TAR
Constant used to identify the TAR archive format.
|
static java.lang.String |
ZIP
Constant used to identify the ZIP archive format.
|
Constructor and Description |
---|
ArchiveStreamFactory() |
Modifier and Type | Method and Description |
---|---|
ArchiveInputStream |
createArchiveInputStream(java.io.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(java.lang.String archiverName,
java.io.InputStream in)
Create an archive input stream from an archiver name and an input stream.
|
ArchiveOutputStream |
createArchiveOutputStream(java.lang.String archiverName,
java.io.OutputStream out)
Create an archive output stream from an archiver name and an input stream.
|
public static final java.lang.String AR
public static final java.lang.String CPIO
public static final java.lang.String JAR
public static final java.lang.String TAR
public static final java.lang.String ZIP
public ArchiveInputStream createArchiveInputStream(java.lang.String archiverName, java.io.InputStream in) throws ArchiveException
archiverName
- the archive name, i.e. "ar", "zip", "tar", "jar" or "cpio"in
- the input streamArchiveException
- if the archiver name is not knownjava.lang.IllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveOutputStream createArchiveOutputStream(java.lang.String archiverName, java.io.OutputStream out) throws ArchiveException
archiverName
- the archive name, i.e. "ar", "zip", "tar", "jar" or "cpio"out
- the output streamArchiveException
- if the archiver name is not knownjava.lang.IllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveInputStream createArchiveInputStream(java.io.InputStream in) throws ArchiveException
in
- the input streamArchiveException
- if the archiver name is not knownjava.lang.IllegalArgumentException
- if the stream is null or does not support mark