public class ArchiveStreamFactory extends java.lang.Object implements ArchiveStreamProvider
final OutputStream out = Files.newOutputStream(output.toPath()); ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out); os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml")); IOUtils.copy(Files.newInputStream(file1.toPath()), os); os.closeArchiveEntry(); os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml")); IOUtils.copy(Files.newInputStream(file2.toPath()), os); os.closeArchiveEntry(); os.close();Decompressing a ZIP-File:
final InputStream is = Files.newInputStream(input.toPath()); ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is); ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry(); OutputStream out = Files.newOutputStream(dir.toPath().resolve(entry.getName())); IOUtils.copy(in, out); out.close(); in.close();
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AR
Constant (value "ar") used to identify the AR archive format.
|
static java.lang.String |
ARJ
Constant (value "arj") used to identify the ARJ archive format.
|
static java.lang.String |
CPIO
Constant (value "cpio") used to identify the CPIO archive format.
|
static java.lang.String |
DUMP
Constant (value "dump") used to identify the Unix DUMP archive format.
|
static java.lang.String |
JAR
Constant (value "jar") used to identify the JAR archive format.
|
static java.lang.String |
SEVEN_Z
Constant (value "7z") used to identify the 7z archive format.
|
static java.lang.String |
TAR
Constant used to identify the TAR archive format.
|
static java.lang.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(java.lang.String encoding)
Create an instance using the specified encoding.
|
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)
Creates an archive input stream from an archiver name and an input stream.
|
ArchiveInputStream |
createArchiveInputStream(java.lang.String archiverName,
java.io.InputStream in,
java.lang.String actualEncoding)
Creates an archive input stream from an archiver name and an input
stream.
|
ArchiveOutputStream |
createArchiveOutputStream(java.lang.String archiverName,
java.io.OutputStream out)
Creates an archive output stream from an archiver name and an output stream.
|
ArchiveOutputStream |
createArchiveOutputStream(java.lang.String archiverName,
java.io.OutputStream out,
java.lang.String actualEncoding)
Creates an archive output stream from an archiver name and an output
stream.
|
static java.lang.String |
detect(java.io.InputStream in)
Try to determine the type of Archiver
|
static java.util.SortedMap<java.lang.String,ArchiveStreamProvider> |
findAvailableArchiveInputStreamProviders()
Constructs a new sorted map from input stream provider names to provider
objects.
|
static java.util.SortedMap<java.lang.String,ArchiveStreamProvider> |
findAvailableArchiveOutputStreamProviders()
Constructs a new sorted map from output stream provider names to provider
objects.
|
java.util.SortedMap<java.lang.String,ArchiveStreamProvider> |
getArchiveInputStreamProviders() |
java.util.SortedMap<java.lang.String,ArchiveStreamProvider> |
getArchiveOutputStreamProviders() |
java.lang.String |
getEntryEncoding()
Returns the encoding to use for arj, jar, zip, dump, cpio and tar
files, or null for the archiver default.
|
java.util.Set<java.lang.String> |
getInputStreamArchiveNames()
Gets all the input stream archive names for this provider
|
java.util.Set<java.lang.String> |
getOutputStreamArchiveNames()
Gets all the output stream archive names for this provider
|
void |
setEntryEncoding(java.lang.String entryEncoding)
Deprecated.
1.10 use
ArchiveStreamFactory(String) to specify the encoding |
public static final java.lang.String AR
public static final java.lang.String ARJ
public static final java.lang.String CPIO
public static final java.lang.String DUMP
public static final java.lang.String JAR
public static final java.lang.String TAR
public static final java.lang.String ZIP
public static final java.lang.String SEVEN_Z
public ArchiveStreamFactory()
public ArchiveStreamFactory(java.lang.String encoding)
encoding
- the encoding to be used.public static java.util.SortedMap<java.lang.String,ArchiveStreamProvider> findAvailableArchiveInputStreamProviders()
The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
public static java.util.SortedMap<java.lang.String,ArchiveStreamProvider> findAvailableArchiveOutputStreamProviders()
The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
public java.lang.String getEntryEncoding()
@Deprecated public void setEntryEncoding(java.lang.String entryEncoding)
ArchiveStreamFactory(String)
to specify the encodingentryEncoding
- the entry encoding, null uses the archiver default.java.lang.IllegalStateException
- if the constructor ArchiveStreamFactory(String)
was used to specify the factory encoding.public ArchiveInputStream createArchiveInputStream(java.lang.String archiverName, java.io.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 streamjava.lang.IllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveInputStream createArchiveInputStream(java.lang.String archiverName, java.io.InputStream in, java.lang.String actualEncoding) throws ArchiveException
ArchiveStreamProvider
createArchiveInputStream
in interface ArchiveStreamProvider
archiverName
- the archive name, i.e.
"ar",
"arj",
"zip",
"tar",
"jar",
"cpio",
"dump"
or
"7z"in
- the input streamactualEncoding
- encoding name or null for the defaultArchiveException
- if the archiver name is not knownStreamingNotSupportedException
- if the format cannot be read from a streampublic 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 knownStreamingNotSupportedException
- if the format cannot be
written to a streamjava.lang.IllegalArgumentException
- if the archiver name or stream is nullpublic ArchiveOutputStream createArchiveOutputStream(java.lang.String archiverName, java.io.OutputStream out, java.lang.String actualEncoding) throws ArchiveException
ArchiveStreamProvider
createArchiveOutputStream
in interface ArchiveStreamProvider
archiverName
- the archive name, i.e.
"ar",
"zip",
"tar",
"jar"
or
"cpio"out
- the output streamactualEncoding
- encoding name or null for the defaultArchiveException
- if the archiver name is not knownStreamingNotSupportedException
- if the format cannot be written to a streampublic ArchiveInputStream createArchiveInputStream(java.io.InputStream in) throws ArchiveException
in
- the input streamArchiveException
- if the archiver name is not knownStreamingNotSupportedException
- if the format cannot be
read from a streamjava.lang.IllegalArgumentException
- if the stream is null or does not support markpublic static java.lang.String detect(java.io.InputStream in) throws ArchiveException
in
- input streamArchiveException
- if an archiver cannot be detected in the streampublic java.util.SortedMap<java.lang.String,ArchiveStreamProvider> getArchiveInputStreamProviders()
public java.util.SortedMap<java.lang.String,ArchiveStreamProvider> getArchiveOutputStreamProviders()
public java.util.Set<java.lang.String> getInputStreamArchiveNames()
ArchiveStreamProvider
getInputStreamArchiveNames
in interface ArchiveStreamProvider
public java.util.Set<java.lang.String> getOutputStreamArchiveNames()
ArchiveStreamProvider
getOutputStreamArchiveNames
in interface ArchiveStreamProvider
Copyright © 2010 - 2020 Adobe. All Rights Reserved