Skip to content

Commit 8df502d

Browse files
committed
Wrap calculations to show how they are constructed
1 parent 4708e98 commit 8df502d

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ 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
123+
((data[offset + 0] & 0xff) << 0) +
123124
((data[offset + 1] & 0xff) << 8) +
124125
((data[offset + 2] & 0xff) << 16) +
125126
((data[offset + 3] & 0xff) << 24);
@@ -137,7 +138,11 @@ public static int readSwappedInteger(final InputStream input) throws IOException
137138
final int value2 = read(input);
138139
final int value3 = read(input);
139140
final int value4 = read(input);
140-
return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16) + ((value4 & 0xff) << 24);
141+
return
142+
((value1 & 0xff) << 0) +
143+
((value2 & 0xff) << 8) +
144+
((value3 & 0xff) << 16) +
145+
((value4 & 0xff) << 24);
141146
}
142147

143148
/**
@@ -180,7 +185,10 @@ public static long readSwappedLong(final InputStream input) throws IOException {
180185
*/
181186
public static short readSwappedShort(final byte[] data, final int offset) {
182187
validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE);
183-
return (short) (((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8));
188+
return (short) (
189+
((data[offset + 0] & 0xff) << 0) +
190+
((data[offset + 1] & 0xff) << 8)
191+
);
184192
}
185193

186194
/**
@@ -191,7 +199,10 @@ public static short readSwappedShort(final byte[] data, final int offset) {
191199
* @throws IOException in case of an I/O problem.
192200
*/
193201
public static short readSwappedShort(final InputStream input) throws IOException {
194-
return (short) (((read(input) & 0xff) << 0) + ((read(input) & 0xff) << 8));
202+
return (short) (
203+
((read(input) & 0xff) << 0) +
204+
((read(input) & 0xff) << 8)
205+
);
195206
}
196207

197208
/**
@@ -206,8 +217,8 @@ public static short readSwappedShort(final InputStream input) throws IOException
206217
public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
207218
validateByteArrayOffset(data, offset, Integer.SIZE / Byte.SIZE);
208219
final long low = ((data[offset + 0] & 0xff) << 0) +
209-
((data[offset + 1] & 0xff) << 8) +
210-
((data[offset + 2] & 0xff) << 16);
220+
((data[offset + 1] & 0xff) << 8) +
221+
((data[offset + 2] & 0xff) << 16);
211222
final long high = data[offset + 3] & 0xff;
212223
return (high << 24) + (0xffffffffL & low);
213224
}
@@ -224,7 +235,9 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
224235
final int value2 = read(input);
225236
final int value3 = read(input);
226237
final int value4 = read(input);
227-
final long low = ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16);
238+
final long low = ((value1 & 0xff) << 0) +
239+
((value2 & 0xff) << 8) +
240+
((value3 & 0xff) << 16);
228241
final long high = value4 & 0xff;
229242
return (high << 24) + (0xffffffffL & low);
230243
}
@@ -240,7 +253,8 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
240253
*/
241254
public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
242255
validateByteArrayOffset(data, offset, Short.SIZE / Byte.SIZE);
243-
return ((data[offset + 0] & 0xff) << 0) + ((data[offset + 1] & 0xff) << 8);
256+
return ((data[offset + 0] & 0xff) << 0) +
257+
((data[offset + 1] & 0xff) << 8);
244258
}
245259

246260
/**
@@ -254,7 +268,8 @@ public static int readSwappedUnsignedShort(final InputStream input) throws IOExc
254268
final int value1 = read(input);
255269
final int value2 = read(input);
256270

257-
return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8);
271+
return ((value1 & 0xff) << 0) +
272+
((value2 & 0xff) << 8);
258273
}
259274

260275
/**
@@ -320,8 +335,10 @@ public static long swapLong(final long value) {
320335
* @return the converted value.
321336
*/
322337
public static short swapShort(final short value) {
323-
return (short) (((value >> 0 & 0xff) << 8) +
324-
((value >> 8 & 0xff) << 0));
338+
return (short) (
339+
((value >> 0 & 0xff) << 8) +
340+
((value >> 8 & 0xff) << 0)
341+
);
325342
}
326343

327344
/**

0 commit comments

Comments
 (0)