Class ArchiveStreamFactory



  • public class ArchiveStreamFactory
    extends Object
    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 = 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();
     
    • Constructor Detail

      • ArchiveStreamFactory

        public ArchiveStreamFactory()
    • Method Detail

      • getEntryEncoding

        public String getEntryEncoding()
        Returns the encoding to use for arj, zip, dump, cpio and tar files, or null for the default.
        Returns:
        entry encoding, or null
        Since:
        1.5
      • setEntryEncoding

        public void setEntryEncoding(String entryEncoding)
        Sets the encoding to use for arj, zip, dump, cpio and tar files. Use null for the default.
        Parameters:
        entryEncoding - the entry encoding, null uses the default.
        Since:
        1.5
      • createArchiveInputStream

        public ArchiveInputStream createArchiveInputStream(InputStream in)
                                                    throws ArchiveException
        Create an archive input stream from an input stream, autodetecting the archive type from the first few bytes of the stream. The InputStream must support marks, like BufferedInputStream.
        Parameters:
        in - the input stream
        Returns:
        the archive input stream
        Throws:
        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