Skip to content

Commit 327d134

Browse files
minor: Remove redundant shift and offset operations in EndianUtils
1 parent 4708e98 commit 327d134

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/main/java/org/apache/commons/io/EndianUtils.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static float readSwappedFloat(final InputStream input) throws IOException
119119
*/
120120
public static int readSwappedInteger(final byte[] data, final int offset) {
121121
validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE);
122-
return ((data[offset + 0] & 0xff) << 0) +
122+
return ((data[offset] & 0xff)) +
123123
((data[offset + 1] & 0xff) << 8) +
124124
((data[offset + 2] & 0xff) << 16) +
125125
((data[offset + 3] & 0xff) << 24);
@@ -137,7 +137,7 @@ public static int readSwappedInteger(final InputStream input) throws IOException
137137
final int value2 = read(input);
138138
final int value3 = read(input);
139139
final int value4 = read(input);
140-
return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24);
140+
return ((value1 & 0xff)) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24);
141141
}
142142

143143
/**
@@ -180,7 +180,7 @@ public static long readSwappedLong(final InputStream input) throws IOException {
180180
*/
181181
public static short readSwappedShort(final byte[] data, final int offset) {
182182
validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE);
183-
return (short) (((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8));
183+
return (short) (((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8));
184184
}
185185

186186
/**
@@ -191,7 +191,7 @@ public static short readSwappedShort(final byte[] data, final int offset) {
191191
* @throws IOException in case of an I/O problem.
192192
*/
193193
public static short readSwappedShort(final InputStream input) throws IOException {
194-
return (short) (((read(input) & 0xff) << 0) + ((read(input) & 0xff) << 8));
194+
return (short) (((read(input) & 0xff)) + ((read(input) & 0xff) << 8));
195195
}
196196

197197
/**
@@ -205,7 +205,7 @@ public static short readSwappedShort(final InputStream input) throws IOException
205205
*/
206206
public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
207207
validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE);
208-
final long low = ((data[offset + 0] & 0xff) << 0) +
208+
final long low = ((data[offset] & 0xff)) +
209209
((data[offset + 1] & 0xff) << 8) +
210210
((data[offset + 2] & 0xff) << 16);
211211
final long high = data[offset + 3] & 0xff;
@@ -224,7 +224,7 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
224224
final int value2 = read(input);
225225
final int value3 = read(input);
226226
final int value4 = read(input);
227-
final long low = ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16);
227+
final long low = ((value1 & 0xff)) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16);
228228
final long high = value4 & 0xff;
229229
return (high << 24) + (0xffffffffL & low);
230230
}
@@ -240,7 +240,7 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
240240
*/
241241
public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
242242
validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE);
243-
return ((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8);
243+
return ((data[offset] & 0xff)) + ((data[offset + 1] & 0xff) << 8);
244244
}
245245

246246
/**
@@ -254,7 +254,7 @@ public static int readSwappedUnsignedShort(final InputStream input) throws IOExc
254254
final int value1 = read(input);
255255
final int value2 = read(input);
256256

257-
return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8);
257+
return ((value1 & 0xff)) + ((value2 & 0xff) << 8);
258258
}
259259

260260
/**
@@ -289,10 +289,10 @@ public static float swapFloat(final float value) {
289289
*/
290290
public static int swapInteger(final int value) {
291291
return
292-
((value >> 0 & 0xff) << 24) +
292+
((value & 0xff) << 24) +
293293
((value >> 8 & 0xff) << 16) +
294294
((value >> 16 & 0xff) << 8) +
295-
((value >> 24 & 0xff) << 0);
295+
((value >> 24 & 0xff));
296296
}
297297

298298
/**
@@ -303,14 +303,14 @@ public static int swapInteger(final int value) {
303303
*/
304304
public static long swapLong(final long value) {
305305
return
306-
((value >> 0 & 0xff) << 56) +
306+
((value & 0xff) << 56) +
307307
((value >> 8 & 0xff) << 48) +
308308
((value >> 16 & 0xff) << 40) +
309309
((value >> 24 & 0xff) << 32) +
310310
((value >> 32 & 0xff) << 24) +
311311
((value >> 40 & 0xff) << 16) +
312312
((value >> 48 & 0xff) << 8) +
313-
((value >> 56 & 0xff) << 0);
313+
((value >> 56 & 0xff));
314314
}
315315

316316
/**
@@ -320,8 +320,8 @@ public static long swapLong(final long value) {
320320
* @return the converted value.
321321
*/
322322
public static short swapShort(final short value) {
323-
return (short) (((value >> 0 & 0xff) << 8) +
324-
((value >> 8 & 0xff) << 0));
323+
return (short) (((value & 0xff) << 8) +
324+
((value >> 8 & 0xff)));
325325
}
326326

327327
/**
@@ -394,7 +394,7 @@ public static void writeSwappedFloat(final OutputStream output, final float valu
394394
*/
395395
public static void writeSwappedInteger(final byte[] data, final int offset, final int value) {
396396
validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE);
397-
data[offset + 0] = (byte) (value >> 0 & 0xff);
397+
data[offset] = (byte) (value & 0xff);
398398
data[offset + 1] = (byte) (value >> 8 & 0xff);
399399
data[offset + 2] = (byte) (value >> 16 & 0xff);
400400
data[offset + 3] = (byte) (value >> 24 & 0xff);
@@ -408,7 +408,7 @@ public static void writeSwappedInteger(final byte[] data, final int offset, fina
408408
* @throws IOException in case of an I/O problem.
409409
*/
410410
public static void writeSwappedInteger(final OutputStream output, final int value) throws IOException {
411-
output.write((byte) (value >> 0 & 0xff));
411+
output.write((byte) (value & 0xff));
412412
output.write((byte) (value >> 8 & 0xff));
413413
output.write((byte) (value >> 16 & 0xff));
414414
output.write((byte) (value >> 24 & 0xff));
@@ -424,7 +424,7 @@ public static void writeSwappedInteger(final OutputStream output, final int valu
424424
*/
425425
public static void writeSwappedLong(final byte[] data, final int offset, final long value) {
426426
validateByteArrayOffset(data, offset, Long.SIZE / Byte.SIZE);
427-
data[offset + 0] = (byte) (value >> 0 & 0xff);
427+
data[offset] = (byte) (value & 0xff);
428428
data[offset + 1] = (byte) (value >> 8 & 0xff);
429429
data[offset + 2] = (byte) (value >> 16 & 0xff);
430430
data[offset + 3] = (byte) (value >> 24 & 0xff);
@@ -442,7 +442,7 @@ public static void writeSwappedLong(final byte[] data, final int offset, final l
442442
* @throws IOException in case of an I/O problem.
443443
*/
444444
public static void writeSwappedLong(final OutputStream output, final long value) throws IOException {
445-
output.write((byte) (value >> 0 & 0xff));
445+
output.write((byte) (value & 0xff));
446446
output.write((byte) (value >> 8 & 0xff));
447447
output.write((byte) (value >> 16 & 0xff));
448448
output.write((byte) (value >> 24 & 0xff));
@@ -462,7 +462,7 @@ public static void writeSwappedLong(final OutputStream output, final long value)
462462
*/
463463
public static void writeSwappedShort(final byte[] data, final int offset, final short value) {
464464
validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE);
465-
data[offset + 0] = (byte) (value >> 0 & 0xff);
465+
data[offset] = (byte) (value & 0xff);
466466
data[offset + 1] = (byte) (value >> 8 & 0xff);
467467
}
468468

@@ -474,7 +474,7 @@ public static void writeSwappedShort(final byte[] data, final int offset, final
474474
* @throws IOException in case of an I/O problem.
475475
*/
476476
public static void writeSwappedShort(final OutputStream output, final short value) throws IOException {
477-
output.write((byte) (value >> 0 & 0xff));
477+
output.write((byte) (value & 0xff));
478478
output.write((byte) (value >> 8 & 0xff));
479479
}
480480

0 commit comments

Comments
 (0)