mx.udlap.kjProtocol.tools
Class DataTypesTools

java.lang.Object
  extended bymx.udlap.kjProtocol.tools.DataTypesTools

public class DataTypesTools
extends java.lang.Object

Class containing method tools to handle byte arrays, numbers, etcetera...

Author:
Oscar Medina Duarte

Constructor Summary
DataTypesTools()
           
 
Method Summary
static byte[] append(byte[] dst, byte[] src)
          Appends contents of src to dst and returns a third byte[]
static byte[] byteCat(byte[] src, byte[] dst)
          Concatenates two byte arays
static byte[] byteSubstring(int start, int end, byte[] src)
          Extracts bytes from start index to end index of source byte array
static java.lang.String byteToHex(byte num)
          Converts a byte to its corresponding String in Hex representation
static java.lang.String byteToHex(byte[] nums)
          Converts a byte array to its corresponding String in Hex representation
static java.lang.String byteToURLHex(byte num)
          Converts a byte to its corresponding String in Hex representation scaped for usage as URL encoding
static java.lang.String byteToURLHex(byte[] nums)
          Converts a byte array to its corresponding String in Hex representation scaped for usage as URL encoding
static java.lang.String hexDump(byte[] data)
          Converts a byte array string into a hex editor representation
static byte[] hexStringToBytes(java.lang.String data)
          Parses a string of Hex values into a byte array with the equivalent numbers.
For example:
static KInteger parseKIntFromByteArray(byte[] src, int position)
          Takes bytes from array to map them into a KInteger
static KString parseKStringFromByteArray(byte[] src, int position)
          Takes bytes from array to map them into a KString
static KTime parseKTimeFromByteArray(byte[] src, int position)
          Description of the Method
static KUUID parseKUUIDFromByteArray(byte[] src, int position)
          Description of the Method
static byte randomByte()
          Returns a random number between 0 and 255
static short signed2unsignedShort(byte signed)
          Converts a signed byte number into a unsigned Short
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataTypesTools

public DataTypesTools()
Method Detail

signed2unsignedShort

public static short signed2unsignedShort(byte signed)
Converts a signed byte number into a unsigned Short

Parameters:
signed - Signed byte
Returns:
Unsigned Short

append

public static byte[] append(byte[] dst,
                            byte[] src)
Appends contents of src to dst and returns a third byte[]

Parameters:
dst - Destination byte array
src - Source Byte array
Returns:
dst + src byte array.

byteSubstring

public static byte[] byteSubstring(int start,
                                   int end,
                                   byte[] src)
Extracts bytes from start index to end index of source byte array

Parameters:
start - Starting position
end - Ending position
src - Source byte array
Returns:
Sub byute array containig bytes start to end from source byte array

byteCat

public static byte[] byteCat(byte[] src,
                             byte[] dst)
Concatenates two byte arays

Parameters:
src - Source byte array
dst - Destination byte array
Returns:
Concatenated byte arrays

byteToHex

public static java.lang.String byteToHex(byte num)
Converts a byte to its corresponding String in Hex representation

Parameters:
num - Byte number
Returns:
Hex representation Sring from num

byteToHex

public static java.lang.String byteToHex(byte[] nums)
Converts a byte array to its corresponding String in Hex representation

Parameters:
nums - Byte array
Returns:
Hex representation Sring from nums

byteToURLHex

public static java.lang.String byteToURLHex(byte num)
Converts a byte to its corresponding String in Hex representation scaped for usage as URL encoding

Parameters:
num - Byte number
Returns:
URL Hex representation Sring from nums

byteToURLHex

public static java.lang.String byteToURLHex(byte[] nums)
Converts a byte array to its corresponding String in Hex representation scaped for usage as URL encoding

Parameters:
nums - Description of the Parameter
Returns:
URL Hex representation Sring from nums

randomByte

public static byte randomByte()
Returns a random number between 0 and 255

Returns:
Random Byte

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String data)
                               throws NotAnHexStringException
Parses a string of Hex values into a byte array with the equivalent numbers.
For example:

A sring like : "1110DEAB"
Would be : byte[] return = {17, 16, 222, 171}

Parameters:
data - A string of the form: [0-9A-Fa-f]+
Returns:
Byte array containing the parsed data
Throws:
NotAnHexStringException - If data is not the form specified above.

parseKIntFromByteArray

public static KInteger parseKIntFromByteArray(byte[] src,
                                              int position)
Takes bytes from array to map them into a KInteger

Parameters:
src - Source byte array
position - First Byte in array to map
Returns:
Last parsed byte from src

parseKTimeFromByteArray

public static KTime parseKTimeFromByteArray(byte[] src,
                                            int position)
Description of the Method

Parameters:
src - Description of the Parameter
position - Description of the Parameter
Returns:
Description of the Return Value

parseKUUIDFromByteArray

public static KUUID parseKUUIDFromByteArray(byte[] src,
                                            int position)
Description of the Method

Parameters:
src - Description of the Parameter
position - Description of the Parameter
Returns:
Description of the Return Value

parseKStringFromByteArray

public static KString parseKStringFromByteArray(byte[] src,
                                                int position)
Takes bytes from array to map them into a KString

Parameters:
src - Source byte array
position - First Byte in array to map
Returns:
Last parsed byte from src

hexDump

public static java.lang.String hexDump(byte[] data)
Converts a byte array string into a hex editor representation

Parameters:
data - byte array
Returns:
Hex editor representation