You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/06/20 18:10:46 UTC
[commons-io] branch master updated: Whitespace and Javadoc
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-io.git
The following commit(s) were added to refs/heads/master by this push:
new c0d254df Whitespace and Javadoc
c0d254df is described below
commit c0d254dffe7e39eaf219f6eb9dfba9f9369f435b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jun 20 14:10:41 2022 -0400
Whitespace and Javadoc
---
.../java/org/apache/commons/io/EndianUtils.java | 104 ++++++++++-----------
1 file changed, 49 insertions(+), 55 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/EndianUtils.java b/src/main/java/org/apache/commons/io/EndianUtils.java
index 9ce2281c..fdb3fd8d 100644
--- a/src/main/java/org/apache/commons/io/EndianUtils.java
+++ b/src/main/java/org/apache/commons/io/EndianUtils.java
@@ -24,7 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
- * Utility code for dealing with different endian systems.
+ * Helps with different endian systems.
* <p>
* Different computer architectures adopt different conventions for
* byte ordering. In so-called "Little Endian" architectures (eg Intel),
@@ -32,8 +32,10 @@ import java.io.OutputStream;
* subsequent bytes at higher addresses. For "Big Endian" architectures
* (eg Motorola), the situation is reversed.
* This class helps you solve this incompatibility.
+ * </p>
* <p>
* Origin of code: Excalibur
+ * </p>
*
* @see org.apache.commons.io.input.SwappedDataInputStream
*/
@@ -47,11 +49,9 @@ public class EndianUtils {
*/
private static int read(final InputStream input) throws IOException {
final int value = input.read();
-
if (EOF == value) {
throw new EOFException("Unexpected EOF reached");
}
-
return value;
}
@@ -63,7 +63,7 @@ public class EndianUtils {
* @return the value read
*/
public static double readSwappedDouble(final byte[] data, final int offset) {
- return Double.longBitsToDouble( readSwappedLong( data, offset ) );
+ return Double.longBitsToDouble(readSwappedLong(data, offset));
}
/**
@@ -85,7 +85,7 @@ public class EndianUtils {
* @return the value read
*/
public static float readSwappedFloat(final byte[] data, final int offset) {
- return Float.intBitsToFloat( readSwappedInteger( data, offset ) );
+ return Float.intBitsToFloat(readSwappedInteger(data, offset));
}
/**
@@ -107,10 +107,10 @@ public class EndianUtils {
* @return the value read
*/
public static int readSwappedInteger(final byte[] data, final int offset) {
- return ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
- ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
- ( ( data[ offset + 2 ] & 0xff ) << 16 ) +
- ( ( data[ offset + 3 ] & 0xff ) << 24 );
+ return ((data[offset + 0] & 0xff) << 0) +
+ ((data[offset + 1] & 0xff) << 8) +
+ ((data[offset + 2] & 0xff) << 16) +
+ ((data[offset + 3] & 0xff) << 24);
}
/**
@@ -125,7 +125,6 @@ public class EndianUtils {
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);
}
@@ -165,8 +164,8 @@ public class EndianUtils {
* @return the value read
*/
public static short readSwappedShort(final byte[] data, final int offset) {
- return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
- ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
+ return (short)(((data[offset + 0] & 0xff) << 0) +
+ ((data[offset + 1] & 0xff) << 8));
}
/**
@@ -189,12 +188,10 @@ public class EndianUtils {
* @return the value read
*/
public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
- final long low = ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
- ( ( data[ offset + 1 ] & 0xff ) << 8 ) +
- ( ( data[ offset + 2 ] & 0xff ) << 16 );
-
- final long high = data[ offset + 3 ] & 0xff;
-
+ final long low = ((data[offset + 0] & 0xff) << 0) +
+ ((data[offset + 1] & 0xff) << 8) +
+ ((data[offset + 2] & 0xff) << 16);
+ final long high = data[offset + 3] & 0xff;
return (high << 24) + (0xffffffffL & low);
}
@@ -210,11 +207,8 @@ public class EndianUtils {
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 high = value4 & 0xff;
-
return (high << 24) + (0xffffffffL & low);
}
@@ -227,8 +221,8 @@ public class EndianUtils {
* @return the value read
*/
public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
- return ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
- ( ( data[ offset + 1 ] & 0xff ) << 8 );
+ return ((data[offset + 0] & 0xff) << 0) +
+ ((data[offset + 1] & 0xff) << 8);
}
/**
@@ -251,7 +245,7 @@ public class EndianUtils {
* @return the converted value
*/
public static double swapDouble(final double value) {
- return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
+ return Double.longBitsToDouble(swapLong(Double.doubleToLongBits(value)));
}
/**
@@ -260,7 +254,7 @@ public class EndianUtils {
* @return the converted value
*/
public static float swapFloat(final float value) {
- return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
+ return Float.intBitsToFloat(swapInteger(Float.floatToIntBits(value)));
}
/**
@@ -270,10 +264,10 @@ public class EndianUtils {
*/
public static int swapInteger(final int value) {
return
- ( ( value >> 0 & 0xff ) << 24 ) +
- ( ( value >> 8 & 0xff ) << 16 ) +
- ( ( value >> 16 & 0xff ) << 8 ) +
- ( ( value >> 24 & 0xff ) << 0 );
+ ((value >> 0 & 0xff) << 24) +
+ ((value >> 8 & 0xff) << 16) +
+ ((value >> 16 & 0xff) << 8) +
+ ((value >> 24 & 0xff) << 0);
}
/**
@@ -283,14 +277,14 @@ public class EndianUtils {
*/
public static long swapLong(final long value) {
return
- ( ( value >> 0 & 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 >> 0 & 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);
}
/**
@@ -299,8 +293,8 @@ public class EndianUtils {
* @return the converted value
*/
public static short swapShort(final short value) {
- return (short) ( ( ( value >> 0 & 0xff ) << 8 ) +
- ( ( value >> 8 & 0xff ) << 0 ) );
+ return (short) (((value >> 0 & 0xff) << 8) +
+ ((value >> 8 & 0xff) << 0));
}
/**
@@ -311,7 +305,7 @@ public class EndianUtils {
* @param value value to write
*/
public static void writeSwappedDouble(final byte[] data, final int offset, final double value) {
- writeSwappedLong( data, offset, Double.doubleToLongBits( value ) );
+ writeSwappedLong(data, offset, Double.doubleToLongBits(value));
}
/**
@@ -333,7 +327,7 @@ public class EndianUtils {
* @param value value to write
*/
public static void writeSwappedFloat(final byte[] data, final int offset, final float value) {
- writeSwappedInteger( data, offset, Float.floatToIntBits( value ) );
+ writeSwappedInteger(data, offset, Float.floatToIntBits(value));
}
/**
@@ -355,10 +349,10 @@ public class EndianUtils {
* @param value value to write
*/
public static void writeSwappedInteger(final byte[] data, final int offset, final int value) {
- data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
- data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
- data[ offset + 2 ] = (byte)( value >> 16 & 0xff );
- data[ offset + 3 ] = (byte)( value >> 24 & 0xff );
+ data[offset + 0] = (byte) (value >> 0 & 0xff);
+ data[offset + 1] = (byte) (value >> 8 & 0xff);
+ data[offset + 2] = (byte) (value >> 16 & 0xff);
+ data[offset + 3] = (byte) (value >> 24 & 0xff);
}
/**
@@ -383,14 +377,14 @@ public class EndianUtils {
* @param value value to write
*/
public static void writeSwappedLong(final byte[] data, final int offset, final long value) {
- data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
- data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
- data[ offset + 2 ] = (byte)( value >> 16 & 0xff );
- data[ offset + 3 ] = (byte)( value >> 24 & 0xff );
- data[ offset + 4 ] = (byte)( value >> 32 & 0xff );
- data[ offset + 5 ] = (byte)( value >> 40 & 0xff );
- data[ offset + 6 ] = (byte)( value >> 48 & 0xff );
- data[ offset + 7 ] = (byte)( value >> 56 & 0xff );
+ data[offset + 0] = (byte) (value >> 0 & 0xff);
+ data[offset + 1] = (byte) (value >> 8 & 0xff);
+ data[offset + 2] = (byte) (value >> 16 & 0xff);
+ data[offset + 3] = (byte) (value >> 24 & 0xff);
+ data[offset + 4] = (byte) (value >> 32 & 0xff);
+ data[offset + 5] = (byte) (value >> 40 & 0xff);
+ data[offset + 6] = (byte) (value >> 48 & 0xff);
+ data[offset + 7] = (byte) (value >> 56 & 0xff);
}
/**
@@ -419,8 +413,8 @@ public class EndianUtils {
* @param value value to write
*/
public static void writeSwappedShort(final byte[] data, final int offset, final short value) {
- data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
- data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
+ data[offset + 0] = (byte)(value >> 0 & 0xff);
+ data[offset + 1] = (byte)(value >> 8 & 0xff);
}
/**