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 54b1c0f85 Refactor magic number
54b1c0f85 is described below
commit 54b1c0f859b057000517ed2247568ad3b3b6da2a
Author: Gary D. Gregory <[email protected]>
AuthorDate: Mon Dec 23 08:51:34 2024 -0500
Refactor magic number
---
.../org/apache/commons/compress/archivers/zip/ZipShort.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
index 935ad4992..38aca48da 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
@@ -26,6 +26,9 @@ import org.apache.commons.compress.utils.ByteUtils;
* @Immutable
*/
public final class ZipShort implements Cloneable, Serializable {
+
+ private static final int SIZE = 2;
+
/**
* ZipShort with a value of 0.
*
@@ -42,7 +45,7 @@ public final class ZipShort implements Cloneable,
Serializable {
* @return the converted int as a byte array in big-endian byte order
*/
public static byte[] getBytes(final int value) {
- final byte[] result = new byte[2];
+ final byte[] result = new byte[SIZE];
putShort(value, result, 0);
return result;
}
@@ -65,7 +68,7 @@ public final class ZipShort implements Cloneable,
Serializable {
* @return the corresponding Java int value
*/
public static int getValue(final byte[] bytes, final int offset) {
- return (int) ByteUtils.fromLittleEndian(bytes, offset, 2);
+ return (int) ByteUtils.fromLittleEndian(bytes, offset, SIZE);
}
/**
@@ -76,7 +79,7 @@ public final class ZipShort implements Cloneable,
Serializable {
* @param offset The offset within the output buffer of the first byte to
be written. must be non-negative and no larger than {@code buf.length-2}
*/
public static void putShort(final int value, final byte[] buf, final int
offset) {
- ByteUtils.toLittleEndian(buf, value, offset, 2);
+ ByteUtils.toLittleEndian(buf, value, offset, SIZE);
}
private final int value;
@@ -139,8 +142,8 @@ public final class ZipShort implements Cloneable,
Serializable {
* @return the value as a two byte array in big-endian byte order
*/
public byte[] getBytes() {
- final byte[] result = new byte[2];
- ByteUtils.toLittleEndian(result, value, 0, 2);
+ final byte[] result = new byte[SIZE];
+ ByteUtils.toLittleEndian(result, value, 0, SIZE);
return result;
}