com.alien.enterpriseRFID.util
Class Converters

java.lang.Object
  extended bycom.alien.enterpriseRFID.util.Converters

public class Converters
extends java.lang.Object

Various converter methods and general utilities for input I/O.

Version:
1.2 April 2008
Author:
David Krull

Constructor Summary
Converters()
           
 
Method Summary
static byte[] fromBinaryString(java.lang.String displayString)
          Convert a displayable string of binary characters to a byte array.
static byte[] fromBinaryStringMSB(java.lang.String displayString)
          Convert a displayable string of binary characters to a byte array.
static byte[] fromHexString(java.lang.String displayString)
          Converts a displayable string of hex characters to a byte array.
static java.lang.String reformatTagID(java.lang.String tagID)
          Converts a tagID string in a "nonstandard" format, to a format acceptable to a reader for programming operations.
static java.lang.String toAsciiString(byte byteValue)
          Converts a single byte to an ASCII character, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate.
static java.lang.String toAsciiString(byte[] byteArray)
          Converts a byte array to a string of ASCII characters, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate.
static java.lang.String toAsciiString(byte[] byteArray, int offset, int length)
          Converts a byte array to a string of ASCII characters, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate.
static java.lang.String toAsciiString(java.lang.String string)
           
static java.lang.String toBinaryString(byte[] byteArray, int padLength)
          Converts a byte array to a string of binary characters.
static java.lang.String toBinaryString(long value, int byteCount)
          Convert a long integer to a string of binary characters.
static java.lang.String toHexString(byte value)
          Converts a byte into a string of hex characters.
static java.lang.String toHexString(byte[] byteArray, int offset, int length, java.lang.String separator)
          Converts a byte array to a string of hex characters, with a given String separating each byte.
static java.lang.String toHexString(byte[] byteArray, int offset, int length, java.lang.String separator, boolean isTagID)
          Converts a byte array to a string of hex characters, with a given String separating each byte.
static java.lang.String toHexString(byte[] byteArray, java.lang.String separator)
          Converts a byte array to a string of hex characters, with a given String separating each byte.
static java.lang.String toHexString(byte[] byteArray, java.lang.String separator, boolean isTagID)
          Converts a byte array to a string of hex characters, with a given String separating each byte.
static java.lang.String toHexString(int value)
          Converts an int into a string of hex characters.
static java.lang.String toHexString(long value, int byteCount)
          Converts a long integer to a string of hex characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converters

public Converters()
Method Detail

toHexString

public static java.lang.String toHexString(byte[] byteArray,
                                           java.lang.String separator)
Converts a byte array to a string of hex characters, with a given String separating each byte.

Parameters:
byteArray - the array of bytes to convert
separator - the separator string
Returns:
a displayable hex string

toHexString

public static java.lang.String toHexString(byte[] byteArray,
                                           java.lang.String separator,
                                           boolean isTagID)
Converts a byte array to a string of hex characters, with a given String separating each byte. This method optionally groups the bytes into pairs, if the isTagID parameter is true.

Parameters:
byteArray - the array of bytes to convert
separator - the separator string
isTagID - puts in a separator every 2 bytes instead of every 1, if true
Returns:
a displayable hex string

toHexString

public static java.lang.String toHexString(byte[] byteArray,
                                           int offset,
                                           int length,
                                           java.lang.String separator)
Converts a byte array to a string of hex characters, with a given String separating each byte. This method allows you to specify the offset into the byte array and number of bytes to convert.

Parameters:
byteArray - the array of bytes to convert
offset - the position within the byte array to start converting
length - the number of bytes to convert
separator - the separator string
Returns:
a displayable hex string

toHexString

public static java.lang.String toHexString(byte[] byteArray,
                                           int offset,
                                           int length,
                                           java.lang.String separator,
                                           boolean isTagID)
Converts a byte array to a string of hex characters, with a given String separating each byte. This method allows you to specify the offset into the byte array, the number of bytes to convert, and whether to group the hex values into pairs.

Parameters:
byteArray - the array of bytes to convert
offset - the position within the byte array to start converting
length - the number of bytes to convert
separator - the separator string
isTagID - puts in a separator every 2 bytes instead of every 1, if true
Returns:
a displayable hex string

toBinaryString

public static java.lang.String toBinaryString(byte[] byteArray,
                                              int padLength)
Converts a byte array to a string of binary characters. The resulting string is padded with leading 0's so that its length is equal to padLength. Use -1 for padLength to turn padding off.

Parameters:
byteArray - the array of bytes to convert
padLength - the minimum length of the resulting binary string
Returns:
a displayable binary string

toHexString

public static java.lang.String toHexString(long value,
                                           int byteCount)
Converts a long integer to a string of hex characters.

Parameters:
value - the integer to convert
byteCount - the number of bytes to convert
Returns:
a displayable hex string

toHexString

public static java.lang.String toHexString(int value)
Converts an int into a string of hex characters. The result is of the form "XX", where XX is the hex representation of the int value. A leading 0 is applied, if the int value is less than 16.

Parameters:
value - the int value to convert to a hex string
Returns:
a displayable hex string

toHexString

public static java.lang.String toHexString(byte value)
Converts a byte into a string of hex characters. The result is of the form "XX", where XX is the hex representation of the byte value. A leading 0 is applied, if the byte value is less than 16.

Parameters:
value - the byte value to convert to a hex string
Returns:
a displayable hex string

toBinaryString

public static java.lang.String toBinaryString(long value,
                                              int byteCount)
Convert a long integer to a string of binary characters.

Parameters:
value - the long integer to convert
byteCount - the number of bytes to convert
Returns:
a displayable binary string

fromHexString

public static byte[] fromHexString(java.lang.String displayString)
Converts a displayable string of hex characters to a byte array. Pieces of the displayString (delimited by spaces) are considered separately, and padded to an even number of bytes. Then every two characters is converted to a byte, with assembly working left to right. Any characters not of hex origin are ignored.

Parameters:
displayString - the display string to convert
Returns:
the byte array from the converted displayString

fromBinaryString

public static byte[] fromBinaryString(java.lang.String displayString)
Convert a displayable string of binary characters to a byte array. Each eight characterss are converted to a byte, with assembly working left to right. Any characters not of binary origin (0,1) are ignored.

Parameters:
displayString - the displayable string to convert
Returns:
the converted byte array

fromBinaryStringMSB

public static byte[] fromBinaryStringMSB(java.lang.String displayString)
Convert a displayable string of binary characters to a byte array. Each eight characterss are converted to a byte, with assembly working left to right. Any characters not of binary origin (0,1) are ignored.

This method differs from fromBinaryString(String) in that any remaining bits past the last 8-bit boundary will be inserted into the most-significant bit positions of the remaining byte.

E.g.
fromBinaryString("1") = 0x01 (00000001), while
fromBinaryStringMSB("1") = 0x80 (10000000)

This is useful for constructing tag mask bytes from an arbitrary number of bit values. The bits in a tag mask are compared to the tag ID from MSB to LSB, so any relevant bits must be in the MSB position.

Parameters:
displayString - the displayable string to convert
Returns:
the converted byte array

toAsciiString

public static java.lang.String toAsciiString(byte[] byteArray,
                                             int offset,
                                             int length)
Converts a byte array to a string of ASCII characters, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate. This method allows you to specify the offset into the byte array, and the number of bytes to convert.

Parameters:
byteArray - the array of bytes to convert
offset - the position within the byte array to start converting
length - the number of bytes to convert
Returns:
the ASCII-representation of the bytes

toAsciiString

public static java.lang.String toAsciiString(byte[] byteArray)
Converts a byte array to a string of ASCII characters, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate.

Parameters:
byteArray - the array of bytes to convert
Returns:
a displayable hex string

toAsciiString

public static java.lang.String toAsciiString(java.lang.String string)

toAsciiString

public static java.lang.String toAsciiString(byte byteValue)
Converts a single byte to an ASCII character, substituting [0xHH] for byte values less than 26, and [cr], [lf], [null] as appropriate.

Parameters:
byteValue - the bytes to convert
Returns:
a displayable hex string

reformatTagID

public static java.lang.String reformatTagID(java.lang.String tagID)
Converts a tagID string in a "nonstandard" format, to a format acceptable to a reader for programming operations. The reader expects tagID to be supplied as a byte string, with individual bytes separated by spaces. This method takes any string in the format "XX XX XX XX", "XXXX XXXX", or "XXXXXXXX", etc. where "X" is one byte, and returns a string formatted as "X X X X X X X X".

First, the original string is compacted, by removing non-hex characters such as spaces, then it is reformatted to have a space between each byte value. It is understood that the original string uses 2-characters to represent each byte, e.g. "A B C D" will be interpreted as "AB CD".

Parameters:
tagID - the original tagID to convert
Returns:
the reformatted tagID string