From aee7641892ee93a451d8eb8972fb87619644536c Mon Sep 17 00:00:00 2001 From: kishor Date: Sun, 8 Feb 2026 12:32:26 +0530 Subject: [PATCH] minor: Remove redundant shift and offset operations in EndianUtils --- .../org/apache/commons/io/EndianUtils.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/commons/io/EndianUtils.java b/src/main/java/org/apache/commons/io/EndianUtils.java index cae06b8345e..e3298afa744 100644 --- a/src/main/java/org/apache/commons/io/EndianUtils.java +++ b/src/main/java/org/apache/commons/io/EndianUtils.java @@ -119,7 +119,7 @@ public static float readSwappedFloat(final InputStream input) throws IOException */ public static int readSwappedInteger(final byte[] data, final int offset) { validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE); - return ((data[offset + 0] & 0xff) << 0) + + return ((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8) + ((data[offset + 2] & 0xff) << 16) + ((data[offset + 3] & 0xff) << 24); @@ -137,7 +137,7 @@ public static int readSwappedInteger(final InputStream input) throws IOException final int value2 = read(input); final int value3 = read(input); final int value4 = read(input); - return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24); + return ((value1 & 0xff)) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24); } /** @@ -180,7 +180,7 @@ public static long readSwappedLong(final InputStream input) throws IOException { */ public static short readSwappedShort(final byte[] data, final int offset) { validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE); - return (short) (((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8)); + return (short) (((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8)); } /** @@ -191,7 +191,7 @@ public static short readSwappedShort(final byte[] data, final int offset) { * @throws IOException in case of an I/O problem. */ public static short readSwappedShort(final InputStream input) throws IOException { - return (short) (((read(input) & 0xff) << 0) + ((read(input) & 0xff) << 8)); + return (short) (((read(input) & 0xff)) + ((read(input) & 0xff) << 8)); } /** @@ -205,7 +205,7 @@ public static short readSwappedShort(final InputStream input) throws IOException */ public static long readSwappedUnsignedInteger(final byte[] data, final int offset) { validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE); - final long low = ((data[offset + 0] & 0xff) << 0) + + final long low = ((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8) + ((data[offset + 2] & 0xff) << 16); final long high = data[offset + 3] & 0xff; @@ -224,7 +224,7 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO final int value2 = read(input); final int value3 = read(input); final int value4 = read(input); - final long low = ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16); + final long low = ((value1 & 0xff)) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16); final long high = value4 & 0xff; return (high << 24) + (0xffffffffL & low); } @@ -240,7 +240,7 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO */ public static int readSwappedUnsignedShort(final byte[] data, final int offset) { validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE); - return ((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8); + return ((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8); } /** @@ -254,7 +254,7 @@ public static int readSwappedUnsignedShort(final InputStream input) throws IOExc final int value1 = read(input); final int value2 = read(input); - return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8); + return ((value1 & 0xff)) + ((value2 & 0xff) << 8); } /** @@ -289,10 +289,10 @@ public static float swapFloat(final float value) { */ public static int swapInteger(final int value) { return - ((value >> 0 & 0xff) << 24) + + ((value & 0xff) << 24) + ((value >> 8 & 0xff) << 16) + ((value >> 16 & 0xff) << 8) + - ((value >> 24 & 0xff) << 0); + ((value >> 24 & 0xff)); } /** @@ -303,14 +303,14 @@ public static int swapInteger(final int value) { */ public static long swapLong(final long value) { return - ((value >> 0 & 0xff) << 56) + + ((value & 0xff) << 56) + ((value >> 8 & 0xff) << 48) + ((value >> 16 & 0xff) << 40) + ((value >> 24 & 0xff) << 32) + ((value >> 32 & 0xff) << 24) + ((value >> 40 & 0xff) << 16) + ((value >> 48 & 0xff) << 8) + - ((value >> 56 & 0xff) << 0); + ((value >> 56 & 0xff)); } /** @@ -320,8 +320,8 @@ public static long swapLong(final long value) { * @return the converted value. */ public static short swapShort(final short value) { - return (short) (((value >> 0 & 0xff) << 8) + - ((value >> 8 & 0xff) << 0)); + return (short) (((value & 0xff) << 8) + + ((value >> 8 & 0xff))); } /** @@ -394,7 +394,7 @@ public static void writeSwappedFloat(final OutputStream output, final float valu */ public static void writeSwappedInteger(final byte[] data, final int offset, final int value) { validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE); - data[offset + 0] = (byte) (value >> 0 & 0xff); + data[offset] = (byte) (value & 0xff); data[offset + 1] = (byte) (value >> 8 & 0xff); data[offset + 2] = (byte) (value >> 16 & 0xff); data[offset + 3] = (byte) (value >> 24 & 0xff); @@ -408,7 +408,7 @@ public static void writeSwappedInteger(final byte[] data, final int offset, fina * @throws IOException in case of an I/O problem. */ public static void writeSwappedInteger(final OutputStream output, final int value) throws IOException { - output.write((byte) (value >> 0 & 0xff)); + output.write((byte) (value & 0xff)); output.write((byte) (value >> 8 & 0xff)); output.write((byte) (value >> 16 & 0xff)); output.write((byte) (value >> 24 & 0xff)); @@ -424,7 +424,7 @@ public static void writeSwappedInteger(final OutputStream output, final int valu */ public static void writeSwappedLong(final byte[] data, final int offset, final long value) { validateByteArrayOffset(data, offset, Long.SIZE / Byte.SIZE); - data[offset + 0] = (byte) (value >> 0 & 0xff); + data[offset] = (byte) (value & 0xff); data[offset + 1] = (byte) (value >> 8 & 0xff); data[offset + 2] = (byte) (value >> 16 & 0xff); data[offset + 3] = (byte) (value >> 24 & 0xff); @@ -442,7 +442,7 @@ public static void writeSwappedLong(final byte[] data, final int offset, final l * @throws IOException in case of an I/O problem. */ public static void writeSwappedLong(final OutputStream output, final long value) throws IOException { - output.write((byte) (value >> 0 & 0xff)); + output.write((byte) (value & 0xff)); output.write((byte) (value >> 8 & 0xff)); output.write((byte) (value >> 16 & 0xff)); output.write((byte) (value >> 24 & 0xff)); @@ -462,7 +462,7 @@ public static void writeSwappedLong(final OutputStream output, final long value) */ public static void writeSwappedShort(final byte[] data, final int offset, final short value) { validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE); - data[offset + 0] = (byte) (value >> 0 & 0xff); + data[offset] = (byte) (value & 0xff); data[offset + 1] = (byte) (value >> 8 & 0xff); } @@ -474,7 +474,7 @@ public static void writeSwappedShort(final byte[] data, final int offset, final * @throws IOException in case of an I/O problem. */ public static void writeSwappedShort(final OutputStream output, final short value) throws IOException { - output.write((byte) (value >> 0 & 0xff)); + output.write((byte) (value & 0xff)); output.write((byte) (value >> 8 & 0xff)); }