public class ArchiveStreamFactory extends Object
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 String |
AR
Constant (value "ar") used to identify the AR archive format.
|
static String |
ARJ
Constant (value "arj") used to identify the ARJ archive format.
|
static String |
CPIO
Constant (value "cpio") used to identify the CPIO archive format.
|
static String |
DUMP
Constant (value "dump") used to identify the Unix DUMP archive format.
|
static String |
JAR
Constant (value "jar") used to identify the JAR archive format.
|
static String |
SEVEN_Z
Constant (value "7z") used to identify the 7z archive format.
|
static String |
TAR
Constant used to identify the TAR archive format.
|
static String |
ZIP
Constant (value "zip") used to identify the ZIP archive format.
|
Constructor and Description |
---|
ArchiveStreamFactory()
Create an instance using the platform default encoding.
|
ArchiveStreamFactory(String encoding)
Create an instance using the specified encoding.
|
Modifier and Type | Method and Description |
---|---|
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 output stream.
|
String |
getEntryEncoding()
Returns the encoding to use for arj, jar, zip, dump, cpio and tar
files, or null for the archiver default.
|
void |
setEntryEncoding(String entryEncoding)
Deprecated.
1.10 use
ArchiveStreamFactory(String) to specify the encoding |
public static final String AR
public static final String ARJ
public static final String CPIO
public static final String DUMP
public static final String JAR
public static final String TAR
public static final String ZIP
public static final String SEVEN_Z
public ArchiveStreamFactory()
public ArchiveStreamFactory(String encoding)
encoding
- the encoding to be used.public String getEntryEncoding()
@Deprecated public void setEntryEncoding(String entryEncoding)
ArchiveStreamFactory(String)
to specify the encodingentryEncoding
- the entry encoding, null uses the archiver default.IllegalStateException
- if the constructor ArchiveStreamFactory(String)
was used to specify the factory encoding.public ArchiveInputStream createArchiveInputStream(String archiverName, InputStream in) throws ArchiveException
archiverName
- the archive name,
i.e. "ar", "arj", "zip", "tar", "jar", "cpio", "dump" or "7z"in
- the input streamArchiveException
- if the archiver name is not knownStreamingNotSupportedException
- if the format cannot be
read from a streamIllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveOutputStream createArchiveOutputStream(String archiverName, 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 knownStreamingNotSupportedException
- if the format cannot be
written to a streamIllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveInputStream createArchiveInputStream(InputStream in) throws ArchiveException
in
- the input streamArchiveException
- if the archiver name is not knownStreamingNotSupportedException
- if the format cannot be
read from a streamIllegalArgumentException
- if the stream is null or does not support markCopyright © 2015 The Apache Software Foundation. All rights reserved.