Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 919CB10FAB for ; Sat, 7 Dec 2013 07:31:07 +0000 (UTC) Received: (qmail 68023 invoked by uid 500); 7 Dec 2013 07:30:55 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 67921 invoked by uid 500); 7 Dec 2013 07:30:43 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 67913 invoked by uid 99); 7 Dec 2013 07:30:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Dec 2013 07:30:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Dec 2013 07:30:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5FA4E23888E7; Sat, 7 Dec 2013 07:30:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1548803 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/compressors/snappy/ test/java/org/apache/commons/compress/compressors/ test/resources/ Date: Sat, 07 Dec 2013 07:30:19 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131207073019.5FA4E23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Sat Dec 7 07:30:18 2013 New Revision: 1548803 URL: http://svn.apache.org/r1548803 Log: COMPRESS-147 unit test for the remaining chunk types along with necessary fixes. The test archive is hand-crafted and the CRCs are wrong right now, will be fixed once I implement CRC verification inside the stream. Added: commons/proper/compress/trunk/src/test/resources/mixed.txt.sz (with props) Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java?rev=1548803&r1=1548802&r2=1548803&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java Sat Dec 7 07:30:18 2013 @@ -125,6 +125,9 @@ public class FramedSnappyCompressorInput int read = -1; if (inUncompressedChunk) { int amount = Math.min(uncompressedBytesRemaining, len); + if (amount == 0) { + return -1; + } read = in.read(b, off, amount); if (read != -1) { uncompressedBytesRemaining -= read; @@ -144,6 +147,7 @@ public class FramedSnappyCompressorInput } private void readNextBlock() throws IOException { + inUncompressedChunk = false; int type = readOneByte(); if (type == -1) { endReached = true; @@ -158,12 +162,14 @@ public class FramedSnappyCompressorInput readNextBlock(); } else if (type >= MIN_UNSKIPPABLE_TYPE && type <= MAX_UNSKIPPABLE_TYPE) { throw new IOException("unskippable chunk with type " + type + + " (hex " + Integer.toHexString(type) + ")" + " detected."); } else if (type == UNCOMPRESSED_CHUNK_TYPE) { - uncompressedBytesRemaining = readSize(); + inUncompressedChunk = true; + uncompressedBytesRemaining = readSize() - 4 /* CRC */; readCrc(); } else if (type == COMPRESSED_CHUNK_TYPE) { - int size = readSize(); + int size = readSize() - 4 /* CRC */; readCrc(); currentCompressedChunk = new SnappyCompressorInputStream(new BoundedInputStream(in, size)); Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java?rev=1548803&r1=1548802&r2=1548803&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTestCase.java Sat Dec 7 07:30:18 2013 @@ -18,7 +18,10 @@ */ package org.apache.commons.compress.compressors; +import static org.junit.Assert.assertArrayEquals; + import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -117,8 +120,8 @@ public final class FramedSnappyTestCase try { FileInputStream gz = new FileInputStream(outputGz); try { - assertTrue(Arrays.equals(IOUtils.toByteArray(sz), - IOUtils.toByteArray(gz))); + assertArrayEquals(IOUtils.toByteArray(sz), + IOUtils.toByteArray(gz)); } finally { gz.close(); } @@ -127,6 +130,28 @@ public final class FramedSnappyTestCase } } + public void testRemainingChunkTypes() throws Exception { + final FileInputStream isSz = new FileInputStream(getFile("mixed.txt.sz")); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + CompressorInputStream in = new FramedSnappyCompressorInputStream(isSz); + IOUtils.copy(in, out); + out.close(); + } finally { + isSz.close(); + } + + assertArrayEquals(new byte[] { '1', '2', '3', '4', + '5', '6', '7', '8', '9', + '5', '6', '7', '8', '9', + '5', '6', '7', '8', '9', + '5', '6', '7', '8', '9', + '5', '6', '7', '8', '9', 10, + '1', '2', '3', '4', + '1', '2', '3', '4', + }, out.toByteArray()); + } + private void testUnarchive(StreamWrapper wrapper) throws Exception { final File input = getFile("bla.tar.sz"); final File output = new File(dir, "bla.tar"); @@ -154,8 +179,8 @@ public final class FramedSnappyTestCase try { FileInputStream orig = new FileInputStream(original); try { - assertTrue(Arrays.equals(IOUtils.toByteArray(written), - IOUtils.toByteArray(orig))); + assertArrayEquals(IOUtils.toByteArray(written), + IOUtils.toByteArray(orig)); } finally { orig.close(); } Added: commons/proper/compress/trunk/src/test/resources/mixed.txt.sz URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/mixed.txt.sz?rev=1548803&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/compress/trunk/src/test/resources/mixed.txt.sz ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream