commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [5/5] commons-compress git commit: make Sonar less unhappy
Date Thu, 06 Jul 2017 07:53:58 GMT
make Sonar less unhappy


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b4445543
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b4445543
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b4445543

Branch: refs/heads/master
Commit: b4445543def1cc905f66334d42f250d5a637a01d
Parents: af48720
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Thu Jul 6 09:53:36 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:53:36 2017 +0200

----------------------------------------------------------------------
 .../commons/compress/archivers/sevenz/CLI.java      |  8 ++++----
 .../compress/archivers/zip/NioZipEncoding.java      | 16 ++++++----------
 2 files changed, 10 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b4445543/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
index 0db5a42..8caac74 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/CLI.java
@@ -64,7 +64,7 @@ public class CLI {
             }
         },
         EXTRACT("Extracting") {
-            private  final byte[] BUF = new byte[8192];
+            private final byte[] buf = new byte[8192];
             @Override
             public void takeAction(final SevenZFile archive, final SevenZArchiveEntry entry)

                 throws IOException {
@@ -86,8 +86,8 @@ public class CLI {
                     final long total = entry.getSize();
                     long off = 0;
                     while (off < total) {
-                        final int toRead = (int) Math.min(total - off, BUF.length);
-                        final int bytesRead = archive.read(BUF, 0, toRead);
+                        final int toRead = (int) Math.min(total - off, buf.length);
+                        final int bytesRead = archive.read(buf, 0, toRead);
                         if (bytesRead < 1) {
                             throw new IOException("reached end of entry "
                                                   + entry.getName()
@@ -96,7 +96,7 @@ public class CLI {
                                                   + total);
                         }
                         off += bytesRead;
-                        fos.write(BUF, 0, bytesRead);
+                        fos.write(buf, 0, bytesRead);
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b4445543/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java b/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
index 323f838..98d26d9 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/NioZipEncoding.java
@@ -41,6 +41,10 @@ class NioZipEncoding implements ZipEncoding, HasCharset {
     private static final char REPLACEMENT = '?';
     private static final byte[] REPLACEMENT_BYTES = { (byte) REPLACEMENT };
     private static final String REPLACEMENT_STRING = String.valueOf(REPLACEMENT);
+    private static final char[] HEX_CHARS = new char[] {
+        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
+    };
+
 
     /**
      * Construct an NioZipEncoding using the given charset.
@@ -86,18 +90,14 @@ class NioZipEncoding implements ZipEncoding, HasCharset {
                 // write the unmappable characters in utf-16
                 // pseudo-URL encoding style to ByteBuffer.
 
-                int spaceForSurrogate = estimateIncrementalEncodingSize(enc, (6 * res.length()));
+                int spaceForSurrogate = estimateIncrementalEncodingSize(enc, 6 * res.length());
                 if (spaceForSurrogate > out.remaining()) {
                     // if the destination buffer isn't over sized, assume that the presence
of one
                     // unmappable character makes it likely that there will be more. Find
all the
                     // un-encoded characters and allocate space based on those estimates.
                     int charCount = 0;
                     for (int i = cb.position() ; i < cb.limit(); i++) {
-                        if (!enc.canEncode(cb.get(i))) {
-                            charCount+= 6;
-                        } else {
-                            charCount++;
-                        }
+                        charCount += !enc.canEncode(cb.get(i)) ? 6 : 1;
                     }
                     int totalExtraSpace = estimateIncrementalEncodingSize(enc, charCount);
                     out = ZipEncodingHelper.growBufferBy(out, totalExtraSpace - out.remaining());
@@ -145,10 +145,6 @@ class NioZipEncoding implements ZipEncoding, HasCharset {
         return o;
     }
 
-    private static final char[] HEX_CHARS = new char[] {
-        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
-    };
-
     private static CharBuffer encodeSurrogate(CharBuffer cb, char c) {
         cb.position(0).limit(6);
         cb.put('%');


Mime
View raw message