|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fosstrak.hal.util.ByteBlock
public class ByteBlock
ByteBlock represents a block of bytes of arbitrary length.
The bytes are stored internally in a byte array, howerver
the bytes are numbered from left to right in contrary to
numbers in hexadecimal format. The bytes in the array are
also considered unsigned in contrast to Java. This allows
the usage of ByteBlock to store output of hardware devices.
The following is an example of the String representation of
a byte block of length 12:
10FF024E6A0000A1611D6400.
In addition the class provides several static byte array support
functions, which allow the usage of ByteBlock without creating
objects of the class.
| Field Summary | |
|---|---|
protected byte[] |
bytes
the byte array to store the byte block |
| Constructor Summary | |
|---|---|
ByteBlock(byte[] bytes)
creates a byte block from the given byte array. |
|
ByteBlock(java.lang.String bytes)
creates a byte block from the given bytes as a String. |
|
| Method Summary | |
|---|---|
static java.lang.String |
byteArrayToHexString(byte[] byteArray)
returns a string with the bytes of the input array in hexadecimal representation. |
static java.lang.String |
byteArrayToHexString(byte[] byteArray,
int length)
returns a string with the byte of the input array in hexadecimal representation trimed/padded to a specific length. |
static int |
bytesToNumber(byte[] b)
converts an unsigned byte array (MSB first, max first four bytes) to a (signed) integer. |
static java.lang.String |
byteToHexString(byte b)
returns a string with the byte in hexadecimal representation. |
static int |
byteToNumber(byte b)
converts an unsigned byte value to a (signed) integer. |
java.lang.Object |
clone()
clones the byte block. |
static int |
compare(byte first,
byte second)
compares two bytes which are interpreted as unsigned bytes. |
static int |
compareRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
compares two given byte block regions. |
boolean |
equals(java.lang.Object o)
checks if two byte blocks are equal or not. |
static boolean |
equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray)
checks if two given byte regions are equal or not. |
static boolean |
equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
checks if two given byte block regions are equal or not. |
byte[] |
getInternalByteArray()
returns a reference to the internal byte array. |
static byte[] |
getRegion(byte[] array,
int offset,
int length)
returns a byte array containing the region of the source byte array. |
int |
hashCode()
calculates a hashcode for the byte block. |
static byte[] |
hexStringToByteArray(java.lang.String hexString)
converts a String of hex bytes to a byte array. |
static byte[] |
hexStringToByteArray(java.lang.String hexString,
int length)
converts a String of hex byte to a byte array of a specific length. |
static byte[] |
numberToByteArray(int n)
creates a byte array out of the given number. |
static byte[] |
numberToByteArray(long n)
creates a byte array out of the given number. |
static byte[] |
numberToByteArray(short n)
creates a byte array out of the given number. |
static void |
replaceRegion(byte[] firstArray,
int offset,
byte[] secondArray)
replaces the region of the first byte array by the bytes of the second byte array. |
static void |
replaceRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
replaces the region of a first byte array by the region of the second byte array. |
static byte[] |
stringConverter(java.lang.String string)
transforms any String into a byte array using UTF8 encoding. |
byte[] |
toByteArray()
gets the byte block as a byte array. |
java.lang.String |
toString()
gets the byte block as a String. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected byte[] bytes
| Constructor Detail |
|---|
public ByteBlock(byte[] bytes)
bytes - the byte array, which is copied into the
internal representation.public ByteBlock(java.lang.String bytes)
bytes - the bytes as a String.| Method Detail |
|---|
public byte[] getInternalByteArray()
public byte[] toByteArray()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Object clone()
clone in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.ObjectObject.equals(java.lang.Object)public int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()public static java.lang.String byteToHexString(byte b)
b - the byte.
public static java.lang.String byteArrayToHexString(byte[] byteArray)
byteArray - the array of bytes.
public static java.lang.String byteArrayToHexString(byte[] byteArray,
int length)
byteArray - length -
public static byte[] hexStringToByteArray(java.lang.String hexString)
hexString - the byte array as a String.
public static byte[] hexStringToByteArray(java.lang.String hexString,
int length)
hexString - length -
public static int byteToNumber(byte b)
b - Unsigned byte value
public static int bytesToNumber(byte[] b)
b -
public static byte[] numberToByteArray(long n)
n=0134A0FF002EC0B1 returns the array
{ 01,34,A0,FF,00,2E,C0,B1 }
n - the number
public static byte[] numberToByteArray(int n)
n - the number
public static byte[] numberToByteArray(short n)
n - the number
public static boolean equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
firstArray - the first byte array.firstOffset - the offset of the first block in the array.secondArray - the second byte array.secondOffset - the offset of the second block in the array.length - the length of the blocks in the arrays.
public static boolean equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray)
firstArray - the first byte array.firstOffset - the offset of the first block in the array.secondArray - the second byte array.
public static int compareRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
firstArray - the first byte array.firstOffset - the offset of the first block in the array.secondArray - the second byte array.secondOffset - the offset of the second block in the array.length - the length of the blocks in the arrays.
public static int compare(byte first,
byte second)
first - the first byte.second - the second byte.
public static byte[] getRegion(byte[] array,
int offset,
int length)
array - the byte array.offset - the offset of the region in the byte array.length - the length of the region in the byte array.
public static void replaceRegion(byte[] firstArray,
int offset,
byte[] secondArray)
firstArray - the first byte array.offset - the offset of the region in the first array.secondArray - the second byte array.
public static void replaceRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
firstArray - the first byte array.firstOffset - the offset of the region in the first array.secondArray - the second byte array.secondOffset - the offset of the region in the second array.length - the length of the region in the arrays.public static byte[] stringConverter(java.lang.String string)
string - the string that has to be converted.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||