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
The following commit(s) were added to refs/heads/master by this push:
new cf68aae72 Deprecate ZipUtil.signedByteToUnsignedInt(byte) in favor of
Byte.toUnsignedInt(byte)
cf68aae72 is described below
commit cf68aae727161b55ff0239730899411ba3f5eef2
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Dec 7 17:00:16 2024 -0500
Deprecate ZipUtil.signedByteToUnsignedInt(byte) in favor of
Byte.toUnsignedInt(byte)
---
src/changes/changes.xml | 3 ++-
.../org/apache/commons/compress/archivers/zip/X7875_NewUnix.java | 7 +++----
.../java/org/apache/commons/compress/archivers/zip/ZipUtil.java | 7 +++----
.../org/apache/commons/compress/archivers/zip/ZipUtilTest.java | 2 +-
4 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 582812745..785e7765d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -53,7 +53,8 @@ The <action> type attribute can be add,update,fix,remove.
<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>
<action type="fix" dev="ggregory" due-to="ddeschenes-1, Gary
Gregory">Throw an IllegalArgumentException when a file name or comment in gzip
parameters encodes to a byte array with a 0 byte #618.</action>
- <action type="fix" dev="ggregory" due-to="Glavo">Update outdated links
in ZipMethod Javadoc #619.</action>
+ <action type="fix" dev="ggregory" due-to="Glavo">Update outdated links
in ZipMethod Javadoc #619.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
ZipUtil.signedByteToUnsignedInt(byte) in favor of
Byte.toUnsignedInt(byte).</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/X7875_NewUnix.java
b/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
index 2941e2d8a..2b1da7203 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
@@ -19,7 +19,6 @@
package org.apache.commons.compress.archivers.zip;
import static org.apache.commons.compress.archivers.zip.ZipUtil.reverse;
-import static
org.apache.commons.compress.archivers.zip.ZipUtil.signedByteToUnsignedInt;
import static
org.apache.commons.compress.archivers.zip.ZipUtil.unsignedIntToSignedByte;
import java.io.Serializable;
@@ -292,8 +291,8 @@ public class X7875_NewUnix implements ZipExtraField,
Cloneable, Serializable {
if (length < 3) {
throw new ZipException("X7875_NewUnix length is too short, only "
+ length + " bytes");
}
- this.version = signedByteToUnsignedInt(data[offset++]);
- final int uidSize = signedByteToUnsignedInt(data[offset++]);
+ this.version = Byte.toUnsignedInt(data[offset++]);
+ final int uidSize = Byte.toUnsignedInt(data[offset++]);
if (uidSize + 3 > length) {
throw new ZipException("X7875_NewUnix invalid: uidSize " + uidSize
+ " doesn't fit into " + length + " bytes");
}
@@ -301,7 +300,7 @@ public class X7875_NewUnix implements ZipExtraField,
Cloneable, Serializable {
offset += uidSize;
this.uid = new BigInteger(1, reverse(uidBytes)); // sign-bit forced
positive
- final int gidSize = signedByteToUnsignedInt(data[offset++]);
+ final int gidSize = Byte.toUnsignedInt(data[offset++]);
if (uidSize + 3 + gidSize > length) {
throw new ZipException("X7875_NewUnix invalid: gidSize " + gidSize
+ " doesn't fit into " + length + " bytes");
}
diff --git
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
index 8c98d361c..917240b8a 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
@@ -307,12 +307,11 @@ public abstract class ZipUtil {
* @param b byte to convert to int
* @return int representation of the provided byte
* @since 1.5
+ * @deprecated Use {@link Byte#toUnsignedInt(byte)}.
*/
+ @Deprecated
public static int signedByteToUnsignedInt(final byte b) {
- if (b >= 0) {
- return b;
- }
- return 256 + b;
+ return Byte.toUnsignedInt(b);
}
/**
diff --git
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
index b4fa80de3..249043f4c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
@@ -248,7 +248,7 @@ public class ZipUtilTest {
int expectedVal = 128;
for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
final byte b = (byte) i;
- assertEquals(expectedVal, ZipUtil.signedByteToUnsignedInt(b));
+ assertEquals(expectedVal, Byte.toUnsignedInt(b));
expectedVal++;
if (expectedVal == 256) {
expectedVal = 0;