pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.util.io
Class ByteUtils

java.lang.Object
  extended by org.torweg.pulse.util.io.ByteUtils

public final class ByteUtils
extends java.lang.Object

provides methods to convert Java primitive types to a byte array representation and vice versa.

Internally it uses DataInputStream and DataOutputStream to do the conversions.

Version:
$Revision: 2022 $
Author:
Thomas Weber

Nested Class Summary
static class ByteUtils.ByteFormatException
          indicates an exception converting a byte array back to a primitive type.
 
Method Summary
static byte[] getBytes(double d)
          returns the double as four bytes (internally converting the double to a long using Double.doubleToLongBits(double)), high byte first.
static byte[] getBytes(float f)
          returns the float as four bytes (internally converting the float to an int using Float.floatToIntBits(float)), high byte first.
static byte[] getBytes(int i)
          returns the int as four bytes, high byte first.
static byte[] getBytes(long l)
          returns the long as eight bytes, high byte first.
static double getDouble(byte[] b)
          returns the first eight bytes of the given byte array as a double, (internally converting the double to a long using Double.longBitsToDouble(long)), high byte first.
static float getFloat(byte[] b)
          returns the first four bytes of the given byte array as an float , (internally converting the float to an int using Float.intBitsToFloat(int)), high byte first.
static int getInt(byte[] b)
          returns the first four bytes of the given byte array as an int (high byte first).
static long getLong(byte[] b)
          returns the first four bytes of the given byte array as an int (high byte first).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBytes

public static byte[] getBytes(int i)
returns the int as four bytes, high byte first.

Parameters:
i - the int
Returns:
a four byte array

getInt

public static int getInt(byte[] b)
returns the first four bytes of the given byte array as an int (high byte first).

Parameters:
b - the byte array
Returns:
an int

getBytes

public static byte[] getBytes(long l)
returns the long as eight bytes, high byte first.

Parameters:
l - the long
Returns:
an eight byte array

getLong

public static long getLong(byte[] b)
returns the first four bytes of the given byte array as an int (high byte first).

Parameters:
b - the byte array
Returns:
an int

getBytes

public static byte[] getBytes(float f)
returns the float as four bytes (internally converting the float to an int using Float.floatToIntBits(float)), high byte first.

Parameters:
f - the float
Returns:
a four byte array

getFloat

public static float getFloat(byte[] b)
returns the first four bytes of the given byte array as an float , (internally converting the float to an int using Float.intBitsToFloat(int)), high byte first.

Parameters:
b - the byte array
Returns:
an int

getBytes

public static byte[] getBytes(double d)
returns the double as four bytes (internally converting the double to a long using Double.doubleToLongBits(double)), high byte first.

Parameters:
d - the double
Returns:
an eight byte array

getDouble

public static double getDouble(byte[] b)
returns the first eight bytes of the given byte array as a double, (internally converting the double to a long using Double.longBitsToDouble(long)), high byte first.

Parameters:
b - the byte array
Returns:
a double