org.gridbus.broker.util
Class Conversion

java.lang.Object
  extended by org.gridbus.broker.util.Conversion

public class Conversion
extends java.lang.Object

This class contains some methods for conversion of byte arrays, hex values etc.


Constructor Summary
Conversion()
           
 
Method Summary
static byte[] bigIntegerToUnsigedBytes(java.math.BigInteger b)
          Converts a BigInteger to a byte array.
static java.lang.String byteArrayToString(byte[] in, java.lang.String encoding)
          Use if you don't want to have to catch a million UnsupportedEncodingExceptions.
static java.lang.String bytesToHexString(byte[] inByteArray)
          Converts a byte[] array into a Hex string
static java.lang.String bytesToHexString(byte[] inByteArray, int offset, int len)
          Converts the given byte array into a hex string representation.
static int bytesToInt(byte[] bytes)
          This function accepts a number of bytes and returns an integer.
static long bytesToLong(byte[] bytes)
          This function accepts a number of bytes and returns a long integer.
static byte[] hexStringToBytes(java.lang.String str)
          This method accepts a hex string and returns a byte array.
static byte[] intToBytes(int i)
          Converts a integer to a byte array representation.
static void longToBytes(long l, byte[] b, int offset, int len)
          Converts a long integer to a byte array representation.
static byte[] longToBytes(long l, int len)
          Converts a long integer to a byte array representation.
static byte[] stringToByteArray(java.lang.String in, java.lang.String encoding)
          Use if you don't want to have to catch a million UnsupportedEncodingExceptions.
static int unsignedByteToInt(byte i)
          Converts a byte in range -128 <= i <= 127 to an int in range 0 <= i <= 255.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Conversion

public Conversion()
Method Detail

bytesToHexString

public static java.lang.String bytesToHexString(byte[] inByteArray)
Converts a byte[] array into a Hex string

Parameters:
inByteArray -
Returns:
string

bytesToHexString

public static java.lang.String bytesToHexString(byte[] inByteArray,
                                                int offset,
                                                int len)
Converts the given byte array into a hex string representation.

Parameters:
inByteArray -
offset -
len -
Returns:
a hex String representation of the byte array.

bytesToLong

public static long bytesToLong(byte[] bytes)
This function accepts a number of bytes and returns a long integer. Note that if the input is 8 bytes, and the high bit of the 0 byte is set, this will come out negative.

Parameters:
bytes - the byte array to convert to a long integer representation.
Returns:
a long integer representation of the byte array.

bytesToInt

public static int bytesToInt(byte[] bytes)
This function accepts a number of bytes and returns an integer. Note that if the input is 4 bytes, and the high bit of the 0 byte is set, this will come out negative.

Parameters:
bytes - the byte array to convert to a long integer representation.
Returns:
a long integer representation of the byte array.

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String str)
This method accepts a hex string and returns a byte array. The string must represent an integer number of bytes.

Parameters:
str - - the hex string to convert to byte array representation.
Returns:
the byte array representation of the hex string.

intToBytes

public static byte[] intToBytes(int i)
Converts a integer to a byte array representation.

Parameters:
i - the integer to convert to byte array representation.
Returns:
the byte array representation of the integer.

longToBytes

public static byte[] longToBytes(long l,
                                 int len)
Converts a long integer to a byte array representation. If the target array is shorter than needed, the hi bytes of the integer will be truncated.

Parameters:
l - the long integer to convert to byte array representation.
len - the size of the byte array to return
Returns:
the byte array representation of the long integer.

longToBytes

public static void longToBytes(long l,
                               byte[] b,
                               int offset,
                               int len)
Converts a long integer to a byte array representation. If the target array is shorter than needed, the hi bytes of the integer will be truncated.

Parameters:
l - the long integer to convert to byte array representation.
b -
offset -
len - the size of the byte array to return

unsignedByteToInt

public static int unsignedByteToInt(byte i)
Converts a byte in range -128 <= i <= 127 to an int in range 0 <= i <= 255.

Parameters:
i - the byte to convert
Returns:
the converted integer

stringToByteArray

public static byte[] stringToByteArray(java.lang.String in,
                                       java.lang.String encoding)
Use if you don't want to have to catch a million UnsupportedEncodingExceptions.

Parameters:
in -
encoding -
Returns:
byte[]

byteArrayToString

public static java.lang.String byteArrayToString(byte[] in,
                                                 java.lang.String encoding)
Use if you don't want to have to catch a million UnsupportedEncodingExceptions.

Parameters:
in -
encoding -
Returns:
String

bigIntegerToUnsigedBytes

public static byte[] bigIntegerToUnsigedBytes(java.math.BigInteger b)
Converts a BigInteger to a byte array.

Parameters:
b - the java.math.BigInteger to convert to a byte array
Returns:
the BigInteger converted to a byte array