Author: bodewig Date: Sun Jun 9 11:49:03 2013 New Revision: 1491185 URL: http://svn.apache.org/r1491185 Log: COMPRESS-111 read-only support for LZMA
Added: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java (with props) commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java (with props) commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma (with props) Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java?rev=1491185&r1=1491184&r2=1491185&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java Sun Jun 9 11:49:03 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); } Added: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java?rev=1491185&view=auto ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java (added) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java Sun Jun 9 11:49:03 2013 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.compressors.lzma; + +import java.io.IOException; +import java.io.InputStream; +import org.tukaani.xz.LZMAInputStream; + +import org.apache.commons.compress.compressors.CompressorInputStream; + +/** + * LZMA decompressor. + * @since 1.6 + */ +public class LZMACompressorInputStream extends CompressorInputStream { + private final InputStream in; + + /** + * Creates a new input stream that decompresses LZMA-compressed data + * from the specified input stream. + * + * @param inputStream where to read the compressed data + * + * @throws IOException if the input is not in the .lzma format, + * the input is corrupt or truncated, the .lzma + * headers specify sizes that are not supported + * by this implementation, or the underlying + * <code>inputStream</code> throws an exception + */ + public LZMACompressorInputStream(InputStream inputStream) + throws IOException { + in = new LZMAInputStream(inputStream); + } + + /** {@inheritDoc} */ + @Override + public int read() throws IOException { + int ret = in.read(); + count(ret == -1 ? -1 : 1); + return ret; + } + + /** {@inheritDoc} */ + @Override + public int read(byte[] buf, int off, int len) throws IOException { + int ret = in.read(buf, off, len); + count(ret); + return ret; + } + + /** {@inheritDoc} */ + @Override + public long skip(long n) throws IOException { + return in.skip(n); + } + + /** {@inheritDoc} */ + @Override + public int available() throws IOException { + return in.available(); + } + + /** {@inheritDoc} */ + @Override + public void close() throws IOException { + in.close(); + } +} Propchange: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/compressors/lzma/LZMACompressorInputStream.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java?rev=1491185&view=auto ============================================================================== --- commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java (added) +++ commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java Sun Jun 9 11:49:03 2013 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress.compressors; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; + +import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; +import org.apache.commons.compress.utils.IOUtils; + +public final class LZMATestCase extends AbstractTestCase { + + public void testLZMAUnarchive() throws Exception { + final File input = getFile("bla.tar.lzma"); + final File output = new File(dir, "bla.tar"); + final InputStream is = new FileInputStream(input); + try { + final CompressorInputStream in = new LZMACompressorInputStream(is); + FileOutputStream out = null; + try { + out = new FileOutputStream(output); + IOUtils.copy(in, out); + } finally { + if (out != null) { + out.close(); + } + in.close(); + } + } finally { + is.close(); + } + } +} Propchange: commons/proper/compress/branches/LZMA/src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma?rev=1491185&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/compress/branches/LZMA/src/test/resources/bla.tar.lzma ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream