|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fosstrak.hal.UnsignedByteArray
public class UnsignedByteArray
UnsignedByteArray represents an array of unsigned bytes of arbitrary length. Since Java does not support unsigned byte arrays this class can be used to send or receive bytes from hardware devices such as RFID readers. In addition, the class provides several static byte array support functions, which allow the usage of UnsignedByteArray without creating objects of the class.
| Field Summary | |
|---|---|
protected byte[] |
bytes
The internal representation of the UnsignedByteArray. |
| Constructor Summary | |
|---|---|
UnsignedByteArray(byte[] bytes)
creates an UnsignedByteArray from the given Java byte array. |
|
UnsignedByteArray(java.lang.String bytes)
creates an UnsignedByteArray from a String representation. |
|
| 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 |
byteToHexString(byte b)
returns a string with the byte in hexadecimal representation. |
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 UnsignedByteArray 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 UnsignedByteArray regions are equal or not. |
static boolean |
equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
checks if two given UnsignedByteArray regions are equal or not. |
protected 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[] |
numberToByteArray(int n)
creates a byte array out of the given int number. |
static byte[] |
numberToByteArray(long n)
creates a byte array out of the given long number. |
static byte[] |
numberToByteArray(short n)
creates a byte array out of the given short 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 UnsignedByteArray as a Java byte array to be interpreted as unsigned bytes. |
java.lang.String |
toString()
gets the UnsignedByteArray as a hex number String representation. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected byte[] bytes
| Constructor Detail |
|---|
public UnsignedByteArray(byte[] bytes)
bytes - the byte array, which is interpreted as unsigned bytespublic UnsignedByteArray(java.lang.String bytes)
bytes - the bytes in hex format as a String| Method Detail |
|---|
protected 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 interpreted as unsigned bytes.
public static byte[] hexStringToByteArray(java.lang.String hexString)
hexString - the byte array as a String.public static byte[] numberToByteArray(long n)
n=0134A0FF002EC0B1 returns the array
{ 01,34,A0,FF,00,2E,C0,B1 }. The bytes in the array
should be interpreted as unsigned bytes.
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 UnsignedByteArray.firstOffset - the offset of the first region in the array.secondArray - the second UnsignedByteArray.secondOffset - the offset of the second region in the array.length - the length of the regions in the arrays.
public static boolean equalsRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray)
firstArray - the first UnsignedByteArray.firstOffset - the offset of the first region in the array.secondArray - the second UnsignedByteArray.
public static int compareRegion(byte[] firstArray,
int firstOffset,
byte[] secondArray,
int secondOffset,
int length)
firstArray - the first UnsignedByteArray.firstOffset - the offset of the first region in the array.secondArray - the second UnsignedByteArray.secondOffset - the offset of the second region in the array.length - the length of the regions 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 | |||||||||