You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/11/26 15:41:05 UTC

(commons-compress) branch master updated (e2a354721 -> 46f7bd8ef)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from e2a354721 Refactor test
     new 673353307 Use a constant instead of a magic number
     new 084f078bb No need for a local variable
     new 480f2a53f Javadoc
     new 46f7bd8ef ZipEightByteInteger.toString() now returns a number string without text prefix, like BigInteger

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  3 +-
 .../archivers/zip/ZipEightByteInteger.java         | 65 +++++++++++-----------
 .../archivers/zip/ZipEightByteIntegerTest.java     |  5 +-
 3 files changed, 38 insertions(+), 35 deletions(-)


(commons-compress) 03/04: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 480f2a53fd5d6248b8cb6944868fcb3b34059a51
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Nov 26 10:30:08 2024 -0500

    Javadoc
---
 .../archivers/zip/ZipEightByteInteger.java         | 56 +++++++++++-----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
index b02bdb6f8..0e205e49b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
@@ -44,8 +44,8 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Gets value as eight bytes in big-endian byte order.
      *
-     * @param value the value to convert
-     * @return value as eight bytes in big-endian byte order
+     * @param value the value to convert.
+     * @return value as eight bytes in big-endian byte order.
      */
     public static byte[] getBytes(final BigInteger value) {
         return getBytes(value.longValue());
@@ -54,50 +54,50 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Gets value as eight bytes in big-endian byte order.
      *
-     * @param value the value to convert
-     * @return value as eight bytes in big-endian byte order
+     * @param value the value to convert.
+     * @return value as eight bytes in big-endian byte order.
      */
     public static byte[] getBytes(final long value) {
         return ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN).putLong(value).array();
     }
 
     /**
-     * Helper method to get the value as a Java long from an eight-byte array
+     * Gets the value as a Java long from an eight-byte array.
      *
-     * @param bytes the array of bytes
-     * @return the corresponding Java long value
+     * @param bytes the array of bytes.
+     * @return the corresponding Java long value.
      */
     public static long getLongValue(final byte[] bytes) {
         return getLongValue(bytes, 0);
     }
 
     /**
-     * Helper method to get the value as a Java long from eight bytes starting at given array offset
+     * Gets the value as a Java long from eight bytes starting at given array offset.
      *
-     * @param bytes  the array of bytes
-     * @param offset the offset to start
-     * @return the corresponding Java long value
+     * @param bytes  the array of bytes.
+     * @param offset the offset to start.
+     * @return the corresponding Java long value.
      */
     public static long getLongValue(final byte[] bytes, final int offset) {
         return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getLong(offset);
     }
 
     /**
-     * Helper method to get the value as a Java long from an eight-byte array
+     * Gets the value as a Java long from an eight-byte array.
      *
-     * @param bytes the array of bytes
-     * @return the corresponding Java BigInteger value
+     * @param bytes the array of bytes.
+     * @return the corresponding Java BigInteger value.
      */
     public static BigInteger getValue(final byte[] bytes) {
         return getValue(bytes, 0);
     }
 
     /**
-     * Helper method to get the value as a Java BigInteger from eight bytes starting at given array offset
+     * Gets the value as a Java BigInteger from eight bytes starting at given array offset.
      *
-     * @param bytes  the array of bytes
-     * @param offset the offset to start
-     * @return the corresponding Java BigInteger value
+     * @param bytes  the array of bytes.
+     * @param offset the offset to start.
+     * @return the corresponding Java BigInteger value.
      */
     public static BigInteger getValue(final byte[] bytes, final int offset) {
         return toUnsignedBigInteger(getLongValue(bytes, offset));
@@ -126,7 +126,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Constructs a new instance from bytes.
      *
-     * @param bytes the bytes to store as a ZipEightByteInteger
+     * @param bytes the bytes to store as a ZipEightByteInteger.
      */
     public ZipEightByteInteger(final byte[] bytes) {
         this(bytes, 0);
@@ -135,8 +135,8 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Constructs a new instance from the eight bytes starting at offset.
      *
-     * @param bytes  the bytes to store as a ZipEightByteInteger
-     * @param offset the offset to start
+     * @param bytes  the bytes to store as a ZipEightByteInteger.
+     * @param offset the offset to start.
      */
     public ZipEightByteInteger(final byte[] bytes, final int offset) {
         this.value = getLongValue(bytes, offset);
@@ -145,7 +145,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Constructs a new instance from a number.
      *
-     * @param value the long to store as a ZipEightByteInteger
+     * @param value the long to store as a ZipEightByteInteger.
      */
     public ZipEightByteInteger(final long value) {
         this.value = value;
@@ -154,8 +154,8 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Override to make two instances with same value equal.
      *
-     * @param o an object to compare
-     * @return true if the objects are equal
+     * @param o an object to compare.
+     * @return true if the objects are equal.
      */
     @Override
     public boolean equals(final Object o) {
@@ -168,7 +168,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Gets value as eight bytes in big-endian byte order.
      *
-     * @return value as eight bytes in big-endian order
+     * @return value as eight bytes in big-endian order.
      */
     public byte[] getBytes() {
         return getBytes(value);
@@ -177,7 +177,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Gets value as Java long.
      *
-     * @return value as a long
+     * @return value as a long.
      */
     public long getLongValue() {
         return value;
@@ -186,7 +186,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Gets value as Java BigInteger.
      *
-     * @return value as a BigInteger
+     * @return value as a BigInteger.
      */
     public BigInteger getValue() {
         return toUnsignedBigInteger(value);
@@ -195,7 +195,7 @@ public final class ZipEightByteInteger implements Serializable {
     /**
      * Override to make two instances with same value equal.
      *
-     * @return the hash code of the value stored in the ZipEightByteInteger
+     * @return the hash code of the value stored in the ZipEightByteInteger.
      */
     @Override
     public int hashCode() {


(commons-compress) 01/04: Use a constant instead of a magic number

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 67335330759eca55144298964a2a2ca0dc6e72b3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Nov 26 10:27:34 2024 -0500

    Use a constant instead of a magic number
---
 .../apache/commons/compress/archivers/zip/ZipEightByteInteger.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
index 2d1cd6545..dac4b958d 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
@@ -30,6 +30,8 @@ import java.nio.ByteOrder;
  */
 public final class ZipEightByteInteger implements Serializable {
 
+    private static final int BYTES = 8;
+
     private static final long serialVersionUID = 1L;
 
     /**
@@ -56,7 +58,7 @@ public final class ZipEightByteInteger implements Serializable {
      * @return value as eight bytes in big-endian byte order
      */
     public static byte[] getBytes(final long value) {
-        final ByteBuffer buffer = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN);
+        final ByteBuffer buffer = ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN);
         buffer.putLong(value);
         return buffer.array();
     }


(commons-compress) 02/04: No need for a local variable

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 084f078bb0b6f199726d74739100b0e153ba52d2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Nov 26 10:30:04 2024 -0500

    No need for a local variable
---
 .../apache/commons/compress/archivers/zip/ZipEightByteInteger.java   | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
index dac4b958d..b02bdb6f8 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
@@ -58,9 +58,7 @@ public final class ZipEightByteInteger implements Serializable {
      * @return value as eight bytes in big-endian byte order
      */
     public static byte[] getBytes(final long value) {
-        final ByteBuffer buffer = ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN);
-        buffer.putLong(value);
-        return buffer.array();
+        return ByteBuffer.allocate(BYTES).order(ByteOrder.LITTLE_ENDIAN).putLong(value).array();
     }
 
     /**
@@ -114,7 +112,6 @@ public final class ZipEightByteInteger implements Serializable {
         }
         return BigInteger.valueOf(value & Long.MAX_VALUE).add(HIGHEST_BIT);
     }
-
     private final long value;
 
     /**


(commons-compress) 04/04: ZipEightByteInteger.toString() now returns a number string without text prefix, like BigInteger

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 46f7bd8efdb8f120d621cdef0ed43e3c777c65a4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Nov 26 10:40:59 2024 -0500

    ZipEightByteInteger.toString() now returns a number string without text
    prefix, like BigInteger
---
 src/changes/changes.xml                                              | 3 ++-
 .../apache/commons/compress/archivers/zip/ZipEightByteInteger.java   | 4 ++--
 .../commons/compress/archivers/zip/ZipEightByteIntegerTest.java      | 5 ++++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 696f56aae..a8af8751e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -52,7 +52,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory, Arturo Bernal">CompressorException extends IOException #605, see also https://github.com/apache/httpcomponents-client/pull/580.</action>
       <action type="fix" dev="ggregory" due-to="Glavo">Update outdated descriptions in IOUtils and IOUtilsTest #612.</action>
       <action type="fix" dev="ggregory" due-to="Glavo">Remove unused local variable in ZipFile #615.</action>
-      <action type="fix" dev="ggregory" due-to="Glavo, Gary Gregory">Optimize ZipEightByteInteger #614.</action> 
+      <action type="fix" dev="ggregory" due-to="Glavo, Gary Gregory">Optimize ZipEightByteInteger #614.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ZipEightByteInteger.toString() now returns a number string without text prefix, like BigInteger.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
index 0e205e49b..63562b03a 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
@@ -30,7 +30,7 @@ import java.nio.ByteOrder;
  */
 public final class ZipEightByteInteger implements Serializable {
 
-    private static final int BYTES = 8;
+    static final int BYTES = 8;
 
     private static final long serialVersionUID = 1L;
 
@@ -204,6 +204,6 @@ public final class ZipEightByteInteger implements Serializable {
 
     @Override
     public String toString() {
-        return "ZipEightByteInteger value: " + Long.toUnsignedString(value);
+        return Long.toUnsignedString(value);
     }
 }
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
index 41d531660..83a686695 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
@@ -149,7 +149,10 @@ public class ZipEightByteIntegerTest {
      */
     @Test
     public void testToString() {
-        assertEquals("ZipEightByteInteger value: 18446744073709551615", newMaxValue().toString());
+        assertEquals("0", ZipEightByteInteger.ZERO.toString());
+        assertEquals("0", ZipEightByteInteger.getValue(new byte[ZipEightByteInteger.BYTES]).toString());
+        assertEquals(Long.toString(Long.MAX_VALUE), new ZipEightByteInteger(BigInteger.valueOf(Long.MAX_VALUE)).toString());
+        assertEquals("18446744073709551615", newMaxValue().toString());
     }
 
     /**