SMILA 1.0 API documentation

org.eclipse.smila.ipc.bon
Class ValueTrafo

java.lang.Object
  extended by org.eclipse.smila.ipc.bon.ValueTrafo

public final class ValueTrafo
extends java.lang.Object

Helper class to convert between byte arrays and scalar values.

Author:
aweber

Method Summary
static double byte2double(byte[] b)
          Reads 8 byte from the byte array and converts them to a double value.
static int byte2int(byte[] b)
          Converts given byte array to positive int value assuming result < 2^31.
static long byte2long(byte[] b)
          Converts given byte array to positive long value.
static java.lang.String byte2string(byte[] b)
          Converts the given byte array to a string by using the default encoding.
static byte[] double2byte(double d)
          Converts the given double value to a byte array.
static int getBytesLength(long v)
          Get minimum number of bytes to store the long value.
static byte[] long2byte(long v)
          Converts positive long value to byte array in Big Endian byte order.
static byte[] long2byte(long v, int byteLength)
          Converts positive long value to byte array in Big Endian byte order, assuming the length of the resulting byte array has been calculated before.
static byte[] string2byte(java.lang.String s)
          Converts the given string to a byte array using the default encoding (utf-8).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

byte2long

public static long byte2long(byte[] b)
Converts given byte array to positive long value.

Parameters:
b - the byte array with length <= 8
Returns:
long value

byte2int

public static int byte2int(byte[] b)
Converts given byte array to positive int value assuming result < 2^31.

Parameters:
b - the byte array with length <= 4
Returns:
int value.

long2byte

public static byte[] long2byte(long v,
                               int byteLength)
Converts positive long value to byte array in Big Endian byte order, assuming the length of the resulting byte array has been calculated before.

Parameters:
v - long value.
byteLength - length of resulting byte array
Returns:
byte array representing the long value

long2byte

public static byte[] long2byte(long v)
Converts positive long value to byte array in Big Endian byte order. The byte array length is the minimum needed to store the value.

Parameters:
v - long value.
Returns:
byte array representing the long value

getBytesLength

public static int getBytesLength(long v)
Get minimum number of bytes to store the long value.

Parameters:
v - long value.
Returns:
minimum length of byte array.

byte2double

public static double byte2double(byte[] b)
Reads 8 byte from the byte array and converts them to a double value.

Parameters:
b - byte array
Returns:
double value. Throws java.nio.BufferUnderflowException, if byte array length < 8.

byte2string

public static java.lang.String byte2string(byte[] b)
Converts the given byte array to a string by using the default encoding.

Parameters:
b - byte array.
Returns:
string value

double2byte

public static byte[] double2byte(double d)
Converts the given double value to a byte array.

Parameters:
d - double value.
Returns:
1 token byte + 8 bytes in Big Endian byte order (IEEE format)

string2byte

public static byte[] string2byte(java.lang.String s)
Converts the given string to a byte array using the default encoding (utf-8).

Parameters:
s - string value.
Returns:
byte representation of string

SMILA 1.0 API documentation