commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r743678 - in /commons/sandbox/compress/trunk/src: main/java/org/apache/commons/compress/compressors/bzip2/ test/resources/
Date Thu, 12 Feb 2009 10:27:11 GMT
Author: bodewig
Date: Thu Feb 12 10:27:10 2009
New Revision: 743678

URL: http://svn.apache.org/viewvc?rev=743678&view=rev
Log:
use proper BZip2 signature, SANDBOX-285

Modified:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
    commons/sandbox/compress/trunk/src/test/resources/bla.txt.bz2

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java?rev=743678&r1=743677&r2=743678&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java
Thu Feb 12 10:27:10 2009
@@ -218,12 +218,9 @@
         if (in.available() == 0) {
             throw new IOException("Empty InputStream");
         }
-        int magic2 = this.in.read();
-        if (magic2 != 'h') {
-            throw new IOException("Stream is not BZip2 formatted: expected 'h'"
-                                  + " as first byte but got '" + (char) magic2
-                                  + "'");
-        }
+        checkMagicChar('B', "first");
+        checkMagicChar('Z', "second");
+        checkMagicChar('h', "third");
 
         int blockSize = this.in.read();
         if ((blockSize < '1') || (blockSize > '9')) {
@@ -237,6 +234,17 @@
         setupBlock();
     }
 
+    private void checkMagicChar(char expected, String position)
+        throws IOException {
+        int magic = this.in.read();
+        if (magic != expected) {
+            throw new IOException("Stream is not BZip2 formatted: expected '"
+                                  + expected + "' as " + position
+                                  + " byte but got '" + (char) magic
+                                  + "'");
+        }
+    }
+
     private void initBlock() throws IOException {
         char magic0 = bsGetUByte();
         char magic1 = bsGetUByte();

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java?rev=743678&r1=743677&r2=743678&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
Thu Feb 12 10:27:10 2009
@@ -405,6 +405,8 @@
         bytesOut = 0;
         nBlocksRandomised = 0;
 
+        bsPutUChar('B');
+        bsPutUChar('Z');
         /* Write `magic' bytes h indicating file-format == huffmanised,
            followed by a digit indicating blockSize100k.
         */

Modified: commons/sandbox/compress/trunk/src/test/resources/bla.txt.bz2
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/resources/bla.txt.bz2?rev=743678&r1=743677&r2=743678&view=diff
==============================================================================
Binary files - no diff available.



Mime
View raw message