commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1531853 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/ArchiveStreamFactory.java archivers/arj/ArjArchiveInputStream.java compressors/gzip/GzipCompressorInputStream.java
Date Mon, 14 Oct 2013 11:10:00 GMT
Author: bodewig
Date: Mon Oct 14 11:10:00 2013
New Revision: 1531853

URL: http://svn.apache.org/r1531853
Log:
clean up ARJ header parsing, addrss PMD issues

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=1531853&r1=1531852&r2=1531853&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Mon Oct 14 11:10:00 2013
@@ -332,7 +332,7 @@ public class ArchiveStreamFactory {
                     if (tais != null) {
                         try {
                             tais.close();
-                        } catch (IOException ignored) {
+                        } catch (IOException ignored) { // NOPMD
                             // ignored
                         }
                     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java?rev=1531853&r1=1531852&r2=1531853&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
Mon Oct 14 11:10:00 2013
@@ -20,7 +20,6 @@ package org.apache.commons.compress.arch
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -85,11 +84,8 @@ public class ArjArchiveInputStream exten
     }
     
     @Override
-    public void close() {
-        try {
-            in.close();
-        } catch (IOException ignored) {
-        }
+    public void close() throws IOException {
+        in.close();
     }
 
     private static void debug(final String message) {
@@ -194,14 +190,13 @@ public class ArjArchiveInputStream exten
         mainHeader.encryptionVersion = firstHeader.readUnsignedByte();
         mainHeader.lastChapter = firstHeader.readUnsignedByte();
         
-        try {
+        if (firstHeaderSize >= 33) {
             mainHeader.arjProtectionFactor = firstHeader.readUnsignedByte();
             mainHeader.arjFlags2 = firstHeader.readUnsignedByte();
             firstHeader.readUnsignedByte();
             firstHeader.readUnsignedByte();
-        } catch (EOFException eof) {
         }
-        
+
         mainHeader.name = readString(basicHeader);
         mainHeader.comment = readString(basicHeader);
         
@@ -256,15 +251,8 @@ public class ArjArchiveInputStream exten
         localFileHeader.firstChapter = firstHeader.readUnsignedByte();
         localFileHeader.lastChapter = firstHeader.readUnsignedByte();
         
-        try {
-            localFileHeader.extendedFilePosition = read32(firstHeader);
-            localFileHeader.dateTimeAccessed = read32(firstHeader);
-            localFileHeader.dateTimeCreated = read32(firstHeader);
-            localFileHeader.originalSizeEvenForVolumes = read32(firstHeader);
-            pushedBackBytes(16);
-        } catch (EOFException eof) {
-        }
-        
+        readExtraData(firstHeaderSize, firstHeader, localFileHeader);
+
         localFileHeader.name = readString(basicHeader);
         localFileHeader.comment = readString(basicHeader);
 
@@ -290,6 +278,20 @@ public class ArjArchiveInputStream exten
         return localFileHeader;
     }
     
+    private void readExtraData(int firstHeaderSize, DataInputStream firstHeader,
+                               LocalFileHeader localFileHeader) throws IOException {
+        if (firstHeaderSize >= 33) {
+            localFileHeader.extendedFilePosition = read32(firstHeader);
+            if (firstHeaderSize >= 45) {
+                localFileHeader.dateTimeAccessed = read32(firstHeader);
+                localFileHeader.dateTimeCreated = read32(firstHeader);
+                localFileHeader.originalSizeEvenForVolumes = read32(firstHeader);
+                pushedBackBytes(12);
+            }
+            pushedBackBytes(4);
+        }
+    }
+
     /**
      * Checks if the signature matches what is expected for an arj file.
      *
@@ -322,7 +324,8 @@ public class ArjArchiveInputStream exten
     @Override
     public ArjArchiveEntry getNextEntry() throws IOException {
         if (currentInputStream != null) {
-            while (currentInputStream.read() >= 0) {
+            while (currentInputStream.read() >= 0) { // NOPMD
+                // drain current input
             }
             currentLocalFileHeader = null;
             currentInputStream = null;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java?rev=1531853&r1=1531852&r2=1531853&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
Mon Oct 14 11:10:00 2013
@@ -210,7 +210,8 @@ public class GzipCompressorInputStream e
     }
 
     private void readToNull(DataInputStream inData) throws IOException {
-        while (inData.readUnsignedByte() != 0x00) {}
+        while (inData.readUnsignedByte() != 0x00) { // NOPMD
+        }
     }
 
     @Override



Mime
View raw message