commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject commons-compress git commit: make Sonar less unhappy
Date Sat, 24 Jun 2017 16:17:30 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master fb9b61804 -> c93d3e1d7


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/c93d3e1d
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/c93d3e1d
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/c93d3e1d

Branch: refs/heads/master
Commit: c93d3e1d7db2971a4e1e7e79d7bf933268cb970e
Parents: fb9b618
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sat Jun 24 18:10:45 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sat Jun 24 18:16:31 2017 +0200

----------------------------------------------------------------------
 .../archivers/zip/ZipArchiveOutputStream.java   |  3 +-
 .../compress/archivers/zip/ZipConstants.java    |  4 +--
 .../utils/FixedLengthBlockOutputStream.java     | 33 +++++++++++---------
 3 files changed, 23 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c93d3e1d/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index 63aeba7..cb594f2 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -760,7 +760,8 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
 
             final Zip64ExtendedInformationExtraField z64 = getZip64Extra(entry.entry);
 
-            ZipEightByteInteger size, compressedSize;
+            ZipEightByteInteger size;
+            ZipEightByteInteger compressedSize;
             if (phased) {
                 // sizes are already known
                 size = new ZipEightByteInteger(entry.entry.getSize());

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c93d3e1d/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
index 23f04a8..c230991 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
@@ -23,8 +23,6 @@ package org.apache.commons.compress.archivers.zip;
  * @since 1.3
  */
 final class ZipConstants {
-    private ZipConstants() { }
-
     /** Masks last eight bits */
     static final int BYTE_MASK = 0xFF;
 
@@ -64,4 +62,6 @@ final class ZipConstants {
      */
     static final long ZIP64_MAGIC = 0xFFFFFFFFL;
 
+    private ZipConstants() { }
+
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c93d3e1d/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
index 8fe6d20..6c93f34 100644
--- a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
@@ -102,7 +102,7 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
 
     @Override
     public void write(int b) throws IOException {
-        if(!isOpen()) {
+        if (!isOpen()) {
             throw new ClosedChannelException();
         }
         buffer.put((byte) b);
@@ -110,10 +110,12 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
     }
 
     @Override
-    public void write(byte[] b, int off, int len) throws IOException {
-        if(!isOpen()) {
+    public void write(byte[] b, final int offset, final int length) throws IOException {
+        if (!isOpen()) {
             throw new ClosedChannelException();
         }
+        int off = offset;
+        int len = length;
         while (len > 0) {
             int n = Math.min(len, buffer.remaining());
             buffer.put(b, off, n);
@@ -125,7 +127,7 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
 
     @Override
     public int write(ByteBuffer src) throws IOException {
-        if(!isOpen()) {
+        if (!isOpen()) {
             throw new ClosedChannelException();
         }
         int srcRemaining = src.remaining();
@@ -161,7 +163,7 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
 
     @Override
     public boolean isOpen() {
-        if(!out.isOpen()) {
+        if (!out.isOpen()) {
             closed.set(true);
         }
         return !closed.get();
@@ -182,7 +184,7 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
         buffer.order(ByteOrder.nativeOrder());
         int bytesToWrite = buffer.remaining();
         if (bytesToWrite > 8) {
-            int align = (buffer.position() & 7);
+            int align = buffer.position() & 7;
             if (align != 0) {
                 int limit = 8 - align;
                 for (int i = 0; i < limit; i++) {
@@ -218,9 +220,12 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
 
         @Override
         public int write(ByteBuffer buffer) throws IOException {
-            assert isOpen() : "somehow trying to write to closed BufferAtATimeOutputChannel";
-            assert buffer.hasArray() :
-                "direct buffer somehow written to BufferAtATimeOutputChannel";
+            if (!isOpen()) {
+                throw new ClosedChannelException();
+            }
+            if (!buffer.hasArray()) {
+                throw new IllegalArgumentException("direct buffer somehow written to BufferAtATimeOutputChannel");
+            }
 
             try {
                 int pos = buffer.position();
@@ -229,11 +234,11 @@ public class FixedLengthBlockOutputStream extends OutputStream implements
Writab
                 buffer.position(buffer.limit());
                 return len;
             } catch (IOException e) {
-                  try {
-                      close();
-                  } finally {
-                      throw e;
-                  }
+                try {
+                    close();
+                } catch (IOException ignored) { //NOSONAR
+                }
+                throw e;
             }
         }
 


Mime
View raw message