Methods Summary |
---|
private static int | read(java.io.InputStream input)Reads the next byte from the input stream.
int value = input.read();
if( -1 == value ) {
throw new EOFException( "Unexpected EOF reached" );
}
return value;
|
public static double | readSwappedDouble(byte[] data, int offset)Reads a "double" value from a byte array at a given offset. The value is
converted to the opposed endian system while reading.
return Double.longBitsToDouble( readSwappedLong( data, offset ) );
|
public static double | readSwappedDouble(java.io.InputStream input)Reads a "double" value from an InputStream. The value is
converted to the opposed endian system while reading.
return Double.longBitsToDouble( readSwappedLong( input ) );
|
public static float | readSwappedFloat(byte[] data, int offset)Reads a "float" value from a byte array at a given offset. The value is
converted to the opposed endian system while reading.
return Float.intBitsToFloat( readSwappedInteger( data, offset ) );
|
public static float | readSwappedFloat(java.io.InputStream input)Reads a "float" value from an InputStream. The value is
converted to the opposed endian system while reading.
return Float.intBitsToFloat( readSwappedInteger( input ) );
|
public static int | readSwappedInteger(byte[] data, int offset)Reads a "int" value from a byte array at a given offset. The value is
converted to the opposed endian system while reading.
return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
( ( data[ offset + 2 ] & 0xff ) << 16 ) +
( ( data[ offset + 3 ] & 0xff ) << 24 ) );
|
public static int | readSwappedInteger(java.io.InputStream input)Reads a "int" value from an InputStream. The value is
converted to the opposed endian system while reading.
int value1 = read( input );
int value2 = read( input );
int value3 = read( input );
int value4 = read( input );
return ( ( value1 & 0xff ) << 0 ) +
( ( value2 & 0xff ) << 8 ) +
( ( value3 & 0xff ) << 16 ) +
( ( value4 & 0xff ) << 24 );
|
public static long | readSwappedLong(byte[] data, int offset)Reads a "long" value from a byte array at a given offset. The value is
converted to the opposed endian system while reading.
long low =
( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
( ( data[ offset + 2 ] & 0xff ) << 16 ) +
( ( data[ offset + 3 ] & 0xff ) << 24 );
long high =
( ( data[ offset + 4 ] & 0xff ) << 0 ) +
( ( data[ offset + 5 ] & 0xff ) << 8 ) +
( ( data[ offset + 6 ] & 0xff ) << 16 ) +
( ( data[ offset + 7 ] & 0xff ) << 24 );
return (high << 32) + (0xffffffffL & low);
|
public static long | readSwappedLong(java.io.InputStream input)Reads a "long" value from an InputStream. The value is
converted to the opposed endian system while reading.
byte[] bytes = new byte[8];
for ( int i=0; i<8; i++ ) {
bytes[i] = (byte) read( input );
}
return readSwappedLong( bytes, 0 );
|
public static short | readSwappedShort(java.io.InputStream input)Reads a "short" value from an InputStream. The value is
converted to the opposed endian system while reading.
return (short)( ( ( read( input ) & 0xff ) << 0 ) +
( ( read( input ) & 0xff ) << 8 ) );
|
public static short | readSwappedShort(byte[] data, int offset)Reads a "short" value from a byte array at a given offset. The value is
converted to the opposed endian system while reading.
return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) );
|
public static long | readSwappedUnsignedInteger(byte[] data, int offset)Reads an unsigned integer (32-bit) value from a byte array at a given
offset. The value is converted to the opposed endian system while
reading.
long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
( ( data[ offset + 2 ] & 0xff ) << 16 ) );
long high = data[ offset + 3 ] & 0xff;
return (high << 24) + (0xffffffffL & low);
|
public static long | readSwappedUnsignedInteger(java.io.InputStream input)Reads a unsigned integer (32-bit) from an InputStream. The value is
converted to the opposed endian system while reading.
int value1 = read( input );
int value2 = read( input );
int value3 = read( input );
int value4 = read( input );
long low = ( ( ( value1 & 0xff ) << 0 ) +
( ( value2 & 0xff ) << 8 ) +
( ( value3 & 0xff ) << 16 ) );
long high = value4 & 0xff;
return (high << 24) + (0xffffffffL & low);
|
public static int | readSwappedUnsignedShort(java.io.InputStream input)Reads a unsigned short (16-bit) from an InputStream. The value is
converted to the opposed endian system while reading.
int value1 = read( input );
int value2 = read( input );
return ( ( ( value1 & 0xff ) << 0 ) +
( ( value2 & 0xff ) << 8 ) );
|
public static int | readSwappedUnsignedShort(byte[] data, int offset)Reads an unsigned short (16-bit) value from a byte array at a given
offset. The value is converted to the opposed endian system while
reading.
return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) );
|
public static double | swapDouble(double value)Converts a "double" value between endian systems.
return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
|
public static float | swapFloat(float value)Converts a "float" value between endian systems.
return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
|
public static int | swapInteger(int value)Converts a "int" value between endian systems.
return
( ( ( value >> 0 ) & 0xff ) << 24 ) +
( ( ( value >> 8 ) & 0xff ) << 16 ) +
( ( ( value >> 16 ) & 0xff ) << 8 ) +
( ( ( value >> 24 ) & 0xff ) << 0 );
|
public static long | swapLong(long value)Converts a "long" value between endian systems.
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 );
|
public static short | swapShort(short value)Converts a "short" value between endian systems.
return (short) ( ( ( ( value >> 0 ) & 0xff ) << 8 ) +
( ( ( value >> 8 ) & 0xff ) << 0 ) );
|
public static void | writeSwappedDouble(byte[] data, int offset, double value)Writes a "double" value to a byte array at a given offset. The value is
converted to the opposed endian system while writing.
writeSwappedLong( data, offset, Double.doubleToLongBits( value ) );
|
public static void | writeSwappedDouble(java.io.OutputStream output, double value)Writes a "double" value to an OutputStream. The value is
converted to the opposed endian system while writing.
writeSwappedLong( output, Double.doubleToLongBits( value ) );
|
public static void | writeSwappedFloat(byte[] data, int offset, float value)Writes a "float" value to a byte array at a given offset. The value is
converted to the opposed endian system while writing.
writeSwappedInteger( data, offset, Float.floatToIntBits( value ) );
|
public static void | writeSwappedFloat(java.io.OutputStream output, float value)Writes a "float" value to an OutputStream. The value is
converted to the opposed endian system while writing.
writeSwappedInteger( output, Float.floatToIntBits( value ) );
|
public static void | writeSwappedInteger(byte[] data, int offset, int value)Writes a "int" value to a byte array at a given offset. The value is
converted to the opposed endian system while writing.
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 );
|
public static void | writeSwappedInteger(java.io.OutputStream output, int value)Writes a "int" value to an OutputStream. The value is
converted to the opposed endian system while writing.
output.write( (byte)( ( value >> 0 ) & 0xff ) );
output.write( (byte)( ( value >> 8 ) & 0xff ) );
output.write( (byte)( ( value >> 16 ) & 0xff ) );
output.write( (byte)( ( value >> 24 ) & 0xff ) );
|
public static void | writeSwappedLong(byte[] data, int offset, long value)Writes a "long" value to a byte array at a given offset. The value is
converted to the opposed endian system while writing.
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 );
|
public static void | writeSwappedLong(java.io.OutputStream output, long value)Writes a "long" value to an OutputStream. The value is
converted to the opposed endian system while writing.
output.write( (byte)( ( value >> 0 ) & 0xff ) );
output.write( (byte)( ( value >> 8 ) & 0xff ) );
output.write( (byte)( ( value >> 16 ) & 0xff ) );
output.write( (byte)( ( value >> 24 ) & 0xff ) );
output.write( (byte)( ( value >> 32 ) & 0xff ) );
output.write( (byte)( ( value >> 40 ) & 0xff ) );
output.write( (byte)( ( value >> 48 ) & 0xff ) );
output.write( (byte)( ( value >> 56 ) & 0xff ) );
|
public static void | writeSwappedShort(java.io.OutputStream output, short value)Writes a "short" value to an OutputStream. The value is
converted to the opposed endian system while writing.
output.write( (byte)( ( value >> 0 ) & 0xff ) );
output.write( (byte)( ( value >> 8 ) & 0xff ) );
|
public static void | writeSwappedShort(byte[] data, int offset, short value)Writes a "short" value to a byte array at a given offset. The value is
converted to the opposed endian system while writing.
data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
|