Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: modified everything to fit to new implementation, creating link to todo list
h1. Component Overview Compress is an API for working with the following files: tar, zip and bzip2 files, bzip2, cpio, ar, gz, jar. h1. Quick Start *compress\* is divided between Compressors and Archivers. While you have to get an Archiver from a factory when just archiving one or more files to the target file (tar), you'll need a Compressor for reducing the files size (bzip2). Please note: There are a stream based API. It's original code in this component came from Avalon's Excalibur, but originally from Ant, as far as life in Apache goes. It has migrated via: Ant \-> Avalon-Excalibur \-> Commons-IO \-> Commons-Compress. More credits can be found in NOTICE.txt file. *compress\* divides the implementation in Compressors and Archivers. For each one an factory is implemented. Basically you have to get the stream implementation from the factory, create an entry, put this into the stream and stream. Some experimental code makes it possible to modify archiver and compressor files. This means you can delete from for example a zip file. Please note: There were discussion of "sponsoring" compress with code from [TrueZip] (https://truezip.dev.java.net/) and of enhancing compress design. At the moment the current implementation is considered as complex by some people. An deeper look at compress ). The result was, not to include any code from this project (see mailinglists). There was a discussion about the complex file based implementation too. The result was to start again with a stream based implementation and move the old one to a branch. More information about the old implementation can be found on the [CompressImplementationDetails] page. h1. Roadmap Compress looks like moving to proper now and prepares for the first release. If you want to help, here is the [CompressRoadmap]. h2. Archiver To pack an archive, you have to get an archiver stream via the [ArchiverFactory]. At the moment it's possible to get a "zip" or a "tar" archiver. Add your files streams to the archiver and call save to store the archivestream. Archiver streams are: ZIP, CPIO, AR, TAR, JAR. h3. Packing Creating a ZIP-File {{{Archive archiver = [ArchiverFactory].getInstancefinal [OutputStream] out = new [FileOutputStream](output); [ArchiveOutputStream] os = new [ArchiveStreamFactory]().createArchiveOutputStream("zip", out); archiveros.addputArchiveEntry(new File("C:\\Temp\\1.html")); archiver.add( new File("C:\\Temp\\1.html.bz2")); archiver.save( new File("C:\\Temp\\ZIPTEST.zip")[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();}}} h3. Unpacking a ZIP-File {{{Archive archiver = [ArchiverFactory].getInstance( new File("C:\\Temp\\ZIPTEST.zip")); archiver.unpack( new File("C:\\Temp\\unpacked\\")final [InputStream] is = new [FileInputStream](input); [ArchiveInputStream] in = new [ArchiveStreamFactory]().createArchiveInputStream("zip", is); [ZipArchiveEntry] entry = (ZipArchiveEntry)in.getNextEntry(); [OutputStream] out = new [FileOutputStream](new File(dir, entry.getName())); IOUtils.copy(in, out); out.close(); in.close();}}} h2. Compressor Same goes for Compressor. At the moment there is only "bz2" supportCompressor streams are: bz2 and gz. h3. Compressing a file {{{Compressor compressor; compressor = [CompressorFactory].getInstance("bz2"); compressor.compressToHere( new File("C:\\Temp\\test.tar"))final [OutputStream] out = new [FileOutputStream](output); [CompressorOutputStream] cos = new [CompressorStreamFactory]().createCompressorOutputStream("bzip2", out); IOUtils.copy(new [FileInputStream](input), cos); cos.close();}}} h3. Decompressing a file {{{Compressor decompressor; decompressor = [CompressorFactory].getInstance("bz2"); decompressor.decompressTo( new File("C:\\Temp\\asf-logo-huge.tar.bz2"), new File("C:\\Temp\\asf-logo-huge.tar")final [InputStream] is = new [FileInputStream](input); [CompressorInputStream] in = new [CompressorStreamFactory]().createCompressorInputStream("bzip2", is); IOUtils.copy(in, new [FileOutputStream](output)); in.close();}}} h1. FAQ |Add your questions/answers here.| h1. TODO - Add delete features - Enhance implementation design