Author: bodewig Date: Sun Sep 22 13:09:29 2013 New Revision: 1525353 URL: http://svn.apache.org/r1525353 Log: XZ for Java 1.4 has been released, merge the LZMA branch.
Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzma/ - copied from r1525352, commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java commons/proper/compress/trunk/src/test/resources/bla.7z - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/resources/bla.7z commons/proper/compress/trunk/src/test/resources/bla.tar.lzma - copied unchanged from r1525352, commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma Modified: commons/proper/compress/trunk/ (props changed) commons/proper/compress/trunk/pom.xml commons/proper/compress/trunk/src/changes/changes.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/ (props changed) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ (props changed) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java commons/proper/compress/trunk/src/site/xdoc/examples.xml commons/proper/compress/trunk/src/site/xdoc/index.xml commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java Propchange: commons/proper/compress/trunk/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/branches/LZMA:r1491183-1525352 Modified: commons/proper/compress/trunk/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/pom.xml?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/pom.xml (original) +++ commons/proper/compress/trunk/pom.xml Sun Sep 22 13:09:29 2013 @@ -60,7 +60,7 @@ These include: bzip2, gzip, pack200, xz <dependency> <groupId>org.tukaani</groupId> <artifactId>xz</artifactId> - <version>1.3</version> + <version>1.4</version> </dependency> </dependencies> Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Sun Sep 22 13:09:29 2013 @@ -51,8 +51,7 @@ The <action> type attribute can be add,u </action> <action type="add" date="2013-05-07" issue="COMPRESS-54" due-to="Damjan Jovanovic"> - Added read-only support for 7z archives that don't use - LZMA compression. + Added support for 7z archives. </action> <action type="add" date="2013-05-19" issue="COMPRESS-226" due-to="Damjan Jovanovic"> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java Sun Sep 22 13:09:29 2013 @@ -31,6 +31,7 @@ import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.tukaani.xz.LZMAInputStream; import org.tukaani.xz.LZMA2InputStream; class Coders { @@ -47,6 +48,7 @@ class Coders { static CoderId[] coderTable = new CoderId[] { new CoderId(new byte[] { (byte)0x00 }, new CopyDecoder()), + new CoderId(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }, new LZMADecoder()), new CoderId(new byte[] { (byte)0x21 }, new LZMA2Decoder()), // FIXME: gives corrupt output //new CoderId(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }, new DeflateDecoder()), @@ -98,6 +100,22 @@ class Coders { } } + static class LZMADecoder extends CoderBase { + @Override + InputStream decode(final InputStream in, final Coder coder, + String password) throws IOException { + byte propsByte = coder.properties[0]; + long dictSize = coder.properties[1]; + for (int i = 1; i < 4; i++) { + dictSize |= (coder.properties[i + 1] << (8 * i)); + } + if (dictSize > LZMAInputStream.DICT_SIZE_MAX) { + throw new IOException("Dictionary larger than 4GiB maximum size"); + } + return new LZMAInputStream(in, -1, propsByte, (int) dictSize); + } + } + // static class DeflateDecoder extends CoderBase { // @Override // InputStream decode(final InputStream in, final Coder coder, final String password) Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar:r1491183-1525352 Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip:r1491183-1525352 Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java Sun Sep 22 13:09:29 2013 @@ -26,6 +26,7 @@ import org.apache.commons.compress.compr import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; +import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; import org.apache.commons.compress.compressors.xz.XZUtils; @@ -83,6 +84,12 @@ public class CompressorStreamFactory { */ public static final String XZ = "xz"; + /** + * Constant used to identify the LZMA compression method. + * @since 1.6 + */ + public static final String LZMA = "lzma"; + private boolean decompressConcatenated = false; /** @@ -156,7 +163,7 @@ public class CompressorStreamFactory { /** * Create a compressor input stream from a compressor name and an input stream. * - * @param name of the compressor, i.e. "gz", "bzip2", "xz", or "pack200" + * @param name of the compressor, i.e. "gz", "bzip2", "xz", "lzma", or "pack200" * @param in the input stream * @return compressor input stream * @throws CompressorException if the compressor name is not known @@ -183,6 +190,10 @@ public class CompressorStreamFactory { return new XZCompressorInputStream(in); } + if (LZMA.equalsIgnoreCase(name)) { + return new LZMACompressorInputStream(in); + } + if (PACK200.equalsIgnoreCase(name)) { return new Pack200CompressorInputStream(in); } Modified: commons/proper/compress/trunk/src/site/xdoc/examples.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/examples.xml?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/site/xdoc/examples.xml (original) +++ commons/proper/compress/trunk/src/site/xdoc/examples.xml Sun Sep 22 13:09:29 2013 @@ -31,11 +31,13 @@ collect multiple entries inside a single (potentially compressed) archive are archiver formats.</p> - <p>The compressor formats supported are gzip, bzip2, xz and + <p>The compressor formats supported are gzip, bzip2, xz, lzma and Pack200, the archiver formats are ar, cpio, tar and zip as well as dump, 7z and arj for which we currently only support reading. Pack200 is a special case as it can only compress JAR files.</p> + + <p>We currently only provide read support for lzma as well.</p> </subsection> <subsection name="Common Notes"> @@ -76,6 +78,10 @@ CompressorInputStream input = new Compre .createCompressorInputStream(originalInput); ]]></source> + <p>Note that there is no way to detect the lzma format so only + the two-arg version of + <code>createCompressorInputStream</code> can be used.</p> + </subsection> <subsection name="Unsupported Features"> @@ -425,6 +431,30 @@ xzIn.close(); ]]></source> </subsection> + <subsection name="lzma"> + + <p>The implementation of this package is provided by the + public domain <a href="http://tukaani.org/xz/java.html">XZ + for Java</a> library.</p> + + <p>Uncompressing a given lzma compressed file (you would + certainly add exception handling and make sure all streams + get closed properly):</p> +<source><![CDATA[ +FileInputStream fin = new FileInputStream("archive.tar.lzma"); +BufferedInputStream in = new BufferedInputStream(fin); +FileOutputStream out = new FileOutputStream("archive.tar"); +LZMACompressorInputStream lzmaIn = new LZMACompressorInputStream(in); +final byte[] buffer = new byte[buffersize]; +int n = 0; +while (-1 != (n = xzIn.read(buffer))) { + out.write(buffer, 0, n); +} +out.close(); +lzmaIn.close(); +]]></source> + </subsection> + <subsection name="7z"> <p>Note that Commons Compress currently only supports Modified: commons/proper/compress/trunk/src/site/xdoc/index.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/index.xml?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/site/xdoc/index.xml (original) +++ commons/proper/compress/trunk/src/site/xdoc/index.xml Sun Sep 22 13:09:29 2013 @@ -27,7 +27,7 @@ <p> The Apache Commons Compress library defines an API for working with ar, cpio, Unix dump, tar, zip, gzip, XZ, Pack200, - bzip2, 7z and arj files. + bzip2, 7z, arj and lzma files. </p> <p> The code in this component has many origins: @@ -64,13 +64,14 @@ by <code>ArchiveEntry</code> instances which in turn usually correspond to single files or directories.</p> - <p>Currently the bzip2, Pack200, XZ and gzip formats are + <p>Currently the bzip2, Pack200, XZ, gzip and lzma formats are supported as compressors where gzip support is mostly provided by the <code>java.util.zip</code> package and Pack200 support by the <code>java.util.jar</code> package of the Java - class library. XZ support is provided by the public + class library. XZ and lzma support is provided by the public domain <a href="http://tukaani.org/xz/java.html">XZ for - Java</a> library.</p> + Java</a> library. As of Commons Compress 1.6 support for + the lzma formats is read-only.</p> <p>The ar, arj, cpio, dump, tar, 7z and zip formats are supported as archivers where the <a href="zip.html">zip</a> Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java?rev=1525353&r1=1525352&r2=1525353&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java Sun Sep 22 13:09:29 2013 @@ -20,6 +20,9 @@ package org.apache.commons.compress.arch import org.apache.commons.compress.AbstractTestCase; public class SevenZFileTest extends AbstractTestCase { + private static String TEST2_CONTENT = "<?xml version = '1.0'?>\r\n<!DOCTYPE" + + " connections>\r\n<meinxml>\r\n\t<leer />\r\n</meinxml>\n"; + public void testAllEmptyFilesArchive() throws Exception { SevenZFile archive = new SevenZFile(getFile("7z-empty-mhc-off.7z")); try { @@ -37,6 +40,27 @@ public class SevenZFileTest extends Abst checkHelloWorld("7z-hello-mhc-off-lzma2.7z"); } + public void test7zUnarchive() throws Exception { + SevenZFile sevenZFile = new SevenZFile(getFile("bla.7z")); + try { + SevenZArchiveEntry entry = sevenZFile.getNextEntry(); + assertEquals("test1.xml", entry.getName()); + entry = sevenZFile.getNextEntry(); + assertEquals("test2.xml", entry.getName()); + byte[] contents = new byte[(int)entry.getSize()]; + int off = 0; + while ((off < contents.length)) { + int bytesRead = sevenZFile.read(contents, off, contents.length - off); + assert(bytesRead >= 0); + off += bytesRead; + } + assertEquals(TEST2_CONTENT, new String(contents, "UTF-8")); + assertNull(sevenZFile.getNextEntry()); + } finally { + sevenZFile.close(); + } + } + private void checkHelloWorld(final String filename) throws Exception { SevenZFile sevenZFile = new SevenZFile(getFile(filename)); try {