Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/main/java/org/apache/commons/io/EndianUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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)));
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);
}

Expand All @@ -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));
}

Expand Down