Class ArchiveStreamFactory

java.lang.Object
org.apache.commons.compress.archivers.ArchiveStreamFactory
All Implemented Interfaces:
ArchiveStreamProvider

public class ArchiveStreamFactory extends Object implements ArchiveStreamProvider
Factory to create Archive[In|Out]putStreams from names or the first bytes of the InputStream. In order to 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 = 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();
 
This class is immutable
provided that the deprecated method setEntryEncoding is not used.
This class is thread-safe
even if the deprecated method setEntryEncoding is used