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 used to identify the AR archive format.
|
static String |
ARJ
Constant used to identify the ARJ 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 |
SEVEN_Z
Constant used to identify the 7z 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 and Description |
|---|
ArchiveStreamFactory()
|
| Modifier and Type | Method and Description |
|---|---|
ArchiveInputStream |
createArchiveInputStream(InputStream
Create an archive input stream from an input stream, autodetecting the archive type from the first few bytes of the stream.
|
ArchiveInputStream |
createArchiveInputStream(String
Create an archive input stream from an archiver name and an input stream.
|
ArchiveOutputStream |
createArchiveOutputStream(String
Create an archive output stream from an archiver name and an input stream.
|
String |
getEntryEncoding()
Returns the encoding to use for arj, zip, dump, cpio and tar files, or null for the default.
|
void |
setEntryEncoding(String
Sets the encoding to use for arj, zip, dump, cpio and tar files.
|
public static final StringAR
public static final StringARJ
public static final StringCPIO
public static final StringDUMP
public static final StringJAR
public static final StringTAR
public static final StringZIP
public static final StringSEVEN_Z
public StringgetEntryEncoding()
public void setEntryEncoding(StringentryEncoding)
entryEncoding - the entry encoding, null uses the default.
public ArchiveInputStreamcreateArchiveInputStream(String archiverName, InputStream in) throws ArchiveException
archiverName - the archive name, i.e. "ar", "arj", "zip", "tar", "jar", "dump" or "cpio"
in - the input stream
ArchiveException - if the archiver name is not known
StreamingNotSupportedException - if the format cannot be read from a stream
IllegalArgumentException - if the archiver name or stream is null
public ArchiveOutputStreamcreateArchiveOutputStream(String archiverName, OutputStream out) throws ArchiveException
archiverName - the archive name, i.e. "ar", "zip", "tar", "jar" or "cpio"
out - the output stream
ArchiveException - if the archiver name is not known
StreamingNotSupportedException - if the format cannot be written to a stream
IllegalArgumentException - if the archiver name or stream is null
public ArchiveInputStreamcreateArchiveInputStream(InputStream in) throws ArchiveException
in - the input stream
ArchiveException - if the archiver name is not known
StreamingNotSupportedException - if the format cannot be read from a stream
IllegalArgumentException - if the stream is null or does not support mark