de.vdheide.utils
Class Bytes

java.lang.Object
  extended byde.vdheide.utils.Bytes

public class Bytes
extends java.lang.Object

Takes an array of bytes (e.g. read from an InputStream) and converts it into a number, assuming MSB order.


Constructor Summary
Bytes(byte[] in)
          Create a new object from an array of bytes and convert to number.
Bytes(byte[] in, int start, int length)
          Create a new object from an array of bytes and convert to a number.
Bytes(long in)
          Create a new object from a long value und convert to array of bytes.
Bytes(long in, int len)
          Create a new object from a long value und convert to array of bytes.
 
Method Summary
static long byteArrayToLong(byte[] in, int start, int length)
          Convert length bytes from an array of bytes starting at position start to a long value.
 byte[] getBytes()
           
 long getValue()
           
static byte[] longToByteArray(long in, int len)
          Convert long value to array of bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bytes

public Bytes(byte[] in)
Create a new object from an array of bytes and convert to number. Result can be read by getValue().

Parameters:
in - Array to convert.

Bytes

public Bytes(byte[] in,
             int start,
             int length)
Create a new object from an array of bytes and convert to a number. Result can be read by getValue().

Parameters:
in - Array to convert.
start - First index in in to read
length - Number of bytes to read

Bytes

public Bytes(long in)
Create a new object from a long value und convert to array of bytes. Result can be read with getBytes().

Parameters:
in - Value to convert

Bytes

public Bytes(long in,
             int len)
Create a new object from a long value und convert to array of bytes. Result can be read with getBytes().

Parameters:
in - Value to convert
len - Length of resulting byte array
Method Detail

getValue

public long getValue()
Returns:
long representation of input

getBytes

public byte[] getBytes()
Returns:
bytes representation of input

byteArrayToLong

public static long byteArrayToLong(byte[] in,
                                   int start,
                                   int length)
Convert length bytes from an array of bytes starting at position start to a long value.

Parameters:
in - Array of bytes to convert
start - First index in in to read
length - Number of bytes to read
Returns:
converted value

longToByteArray

public static byte[] longToByteArray(long in,
                                     int len)
Convert long value to array of bytes.

Parameters:
in - Long value to convert
len - Length of resulting byte array. -1 for minimum length needed.
Returns:
Newly created array of bytes with enough elements to hold the input First entry contains the MSB.