public class Utility
extends java.lang.Object
Constructor and Description |
---|
Utility()
default constructor.
|
Modifier and Type | Method and Description |
---|---|
static int |
bytesToInt(byte[] buffer)
converts 4 bytes to an integer.
|
static int |
bytesToInt(byte[] buffer,
int index)
converts the 4 bytes starting at the specified index to an integer.
|
static short |
bytesToShort(byte[] data)
converts 2 bytes to a short.
|
static short |
bytesToShort(byte[] buffer,
int index)
converts the 2 bytes starting at the specified index to a short.
|
static int |
bytesToSynchsafeInt(byte[] buffer,
int index)
converts the 4 bytes starting at the specified index to a synchsafe integer.
|
static short |
bytesToSynchsafeShort(byte[] buffer,
int index)
converts the 2 bytes starting at the specified index to a synchsafe short.
|
static java.lang.String |
formateDate(java.util.Date date)
formats a date as YYYYMMDD.
|
static java.lang.String |
hex(byte data)
formats a single byte as a 2 digit hex value, ie, 0xbb, where 0 < b < F.
example: decimal: 12 -> hex: 0C example: decimal: 178 -> hex: B2 |
static java.lang.String |
hex(byte[] data)
formats raw binary byte data as a sequence of bytes in the format 0xbb 0xbb ...
|
static java.lang.String |
hex(byte[] data,
int indent)
formats raw binary byte data as a sequence of bytes in the format 0xbb 0xbb ...
|
static byte[] |
intToBytes(int n)
converts an integer value to a 4 byte array.
|
static int |
littleEndianBytesToInt(byte[] bytes,
int index)
converts the 4 little endian bytes starting at the specified index to an integer.
|
static java.lang.String |
pad(int numSpaces)
gets a string consisting of the specified number of blank spaces which can be used for padding (left or right) in order to format some output (ie, make columns line up, etc).
|
static byte[] |
shortToBytes(int n)
converts a short value to a 2 byte array.
|
static byte[] |
synchsafeIntToBytes(int n)
converts a synchsafe integer value to a 4 byte array.
|
public static java.lang.String formateDate(java.util.Date date)
date
- the date to format. If null, then the today's date is used.public static java.lang.String hex(byte data)
data
- byte data whose value will be converted to hex.
public static java.lang.String hex(byte[] data)
data
- raw binary data to be printed.
public static java.lang.String hex(byte[] data, int indent)
data
- raw binary data to be printed.indent
- number of spaces to indent each line of output before displaying the hex bytes.
public static java.lang.String pad(int numSpaces)
numSpaces
- number of spaces to return.public static byte[] intToBytes(int n)
n
- the integer value to be converted to a byte array.public static int bytesToInt(byte[] buffer)
buffer
- the byte array from which the next four sequential bytes will be converted to an integer.public static int littleEndianBytesToInt(byte[] bytes, int index)
bytes
- the byte array from which the next four sequential bytes will be converted to an integer.index
- specifies that the bytes at index, index + 1, index +2, and index + 3 will be converted to an integer.public static int bytesToInt(byte[] buffer, int index)
buffer
- the byte array from which the next four sequential bytes will be converted to an integer.index
- specifies that the bytes at index, index + 1, index +2, and index + 3 will be converted to an integer.public static int bytesToSynchsafeInt(byte[] buffer, int index)
buffer
- the byte array from which the next four sequential bytes will be converted to a synchsafe integer.index
- specifies that the bytes at index, index + 1, index +2, and index + 3 will be converted to a synchsafe integer.public static byte[] synchsafeIntToBytes(int n)
n
- the synchsafe integer value to be converted to a byte array.public static byte[] shortToBytes(int n)
n
- the short value to be converted to a byte array.public static short bytesToShort(byte[] data)
data
- the byte array from which the next two sequential bytes will be converted to a short.public static short bytesToShort(byte[] buffer, int index)
buffer
- the byte array from which the next to sequential bytes will be converted to a short.index
- specifies that the bytes at index and at index + 1 will be converted to a short.public static short bytesToSynchsafeShort(byte[] buffer, int index)
buffer
- the byte array from which the next to sequential bytes will be converted to a synchsafe short.index
- specifies that the bytes at index and at index + 1 will be converted to a synchsafe short.