|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xins.common.text.HexConverter
Utility class for converting numbers to unsigned hex strings and vice versa.
Method Summary | |
static boolean |
isHexDigit(char c)
Checks if the specified character is a hexadecimal digit. |
static byte[] |
parseHexBytes(String s,
int index,
int length)
Parses the specified string as a set of hex digits and converts it to a byte array. |
static int |
parseHexInt(String s)
Parses the specified 8-digit unsigned hex string. |
static int |
parseHexInt(String s,
int index)
Parses the 8-digit unsigned hex number in the specified string. |
static long |
parseHexLong(String s)
Parses the specified 16-digit unsigned hex string. |
static long |
parseHexLong(String s,
int index)
Parses the 16-digit unsigned hex number in the specified string. |
static String |
toHexString(byte n)
Converts the specified byte to an unsigned number hex
string. |
static String |
toHexString(byte[] input)
Converts the specified byte array to an unsigned number hex
string. |
static String |
toHexString(char n)
Converts the specified char to an unsigned number hex
string. |
static void |
toHexString(FastStringBuffer buffer,
byte n)
Converts the specified byte to unsigned number and appends
it to the specified string buffer. |
static void |
toHexString(FastStringBuffer buffer,
char n)
Converts the specified char to unsigned number and appends
it to the specified string buffer. |
static void |
toHexString(FastStringBuffer buffer,
int n)
Converts the specified int to unsigned number and appends
it to the specified string buffer. |
static void |
toHexString(FastStringBuffer buffer,
long n)
Converts the specified long to unsigned number and appends
it to the specified string buffer. |
static void |
toHexString(FastStringBuffer buffer,
short n)
Converts the specified short to unsigned number and appends
it to the specified string buffer. |
static String |
toHexString(int n)
Converts the specified int to an unsigned number hex
string. |
static String |
toHexString(long n)
Convert the specified long to an unsigned number hex
string. |
static String |
toHexString(short n)
Converts the specified short to an unsigned number hex
string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static final boolean isHexDigit(char c)
'0'
to '9'
'a'
to 'f'
'A'
to 'F'
c
- the character to check.
true
if the specified character is a hexadecimal digit,
false
otherwise.public static String toHexString(byte[] input) throws IllegalArgumentException
byte
array to an unsigned number hex
string. The number of characters in the returned string will always be
equal to the number of input bytes times 2.
input
- the byte[]
array to be converted to a hex string.
null
, the length is always 2
times the length of the input array
(i.e. return.
length()
== (input.length * 2)
).
IllegalArgumentException
- if n == null || n.length < 1
.public static String toHexString(byte n)
byte
to an unsigned number hex
string. The returned string will always consist of 2 hex characters,
a zero will be prepended if necessary.
n
- the number to be converted to a hex string.
null
, the length is always 2
(i.e. return.
length()
== 2
).public static String toHexString(short n)
short
to an unsigned number hex
string. The returned string will always consist of 4 hex characters,
zeroes will be prepended as necessary.
n
- the number to be converted to a hex string.
null
, the length is always 4
(i.e. return.
length()
== 4
).public static String toHexString(char n)
char
to an unsigned number hex
string. The returned string will always consist of 4 hex characters,
zeroes will be prepended as necessary.
n
- the character to be converted to a hex string.
null
, the length is always 4
(i.e. return.
length()
== 4
).public static String toHexString(int n)
int
to an unsigned number hex
string. The returned string will always consist of 8 hex characters,
zeroes will be prepended as necessary.
n
- the number to be converted to a hex string.
null
, the length is always 8
(i.e. return.
length()
== 8
).public static String toHexString(long n)
long
to an unsigned number hex
string. The returned string will always consist of 16 hex characters,
zeroes will be prepended as necessary.
n
- the number to be converted to a hex string.
null
, the length is always 16
(i.e. return.
length()
== 16
).public static void toHexString(FastStringBuffer buffer, byte n) throws IllegalArgumentException
byte
to unsigned number and appends
it to the specified string buffer. Exactly 2 characters will be
appended, both between '0'
to '9'
or between
'a'
and 'f'
.
buffer
- the string buffer to append to, cannot be null
.n
- the number to be converted to a hex string.
IllegalArgumentException
- if buffer == null
.public static void toHexString(FastStringBuffer buffer, short n) throws IllegalArgumentException
short
to unsigned number and appends
it to the specified string buffer. Exactly 4 characters will be
appended, all between '0'
to '9'
or between
'a'
and 'f'
.
buffer
- the string buffer to append to, cannot be null
.n
- the number to be converted to a hex string.
IllegalArgumentException
- if buffer == null
.public static void toHexString(FastStringBuffer buffer, char n) throws IllegalArgumentException
char
to unsigned number and appends
it to the specified string buffer. Exactly 4 characters will be
appended, all between '0'
to '9'
or between
'a'
and 'f'
.
buffer
- the string buffer to append to, cannot be null
.n
- the number to be converted to a hex string.
IllegalArgumentException
- if buffer == null
.public static void toHexString(FastStringBuffer buffer, int n) throws IllegalArgumentException
int
to unsigned number and appends
it to the specified string buffer. Exactly 8 characters will be
appended, all between '0'
to '9'
or between
'a'
and 'f'
.
buffer
- the string buffer to append to, cannot be null
.n
- the number to be converted to a hex string.
IllegalArgumentException
- if buffer == null
.public static void toHexString(FastStringBuffer buffer, long n) throws IllegalArgumentException
long
to unsigned number and appends
it to the specified string buffer. Exactly 16 characters will be
appended, all between '0'
to '9'
or between
'a'
and 'f'
.
buffer
- the string buffer to append to, cannot be null
.n
- the number to be converted to a hex string.
IllegalArgumentException
- if buffer == null
.public static byte[] parseHexBytes(String s, int index, int length) throws IllegalArgumentException, NumberFormatException
s
- the hexadecimal string, cannot be null
.index
- the starting index in the string, must be >= 0.length
- the number of characters to convert in the string, must be >= 0.
IllegalArgumentException
- if s == null || index < 0 || length < 1 || s.length()
< index + length
).
NumberFormatException
- if any of the characters in the specified range of the string is not
a hex digit ('0'
to '9'
,
'a'
to 'f'
and
'A'
to 'F'
).public static int parseHexInt(String s, int index) throws IllegalArgumentException, NumberFormatException
s
- the hexadecimal string, cannot be null
.index
- the starting index in the string, must be >= 0.
IllegalArgumentException
- if s == null
|| index < 0
|| s.length()
< index + 8
).
NumberFormatException
- if any of the characters in the specified range of the string is not
a hex digit ('0'
to '9'
and
'a'
to 'f'
).public static int parseHexInt(String s) throws IllegalArgumentException, NumberFormatException
s
- the hexadecimal string, cannot be null
and must have
size 8
(i.e. s.
length()
== 8
).
IllegalArgumentException
- if s == null || s.
length()
!= 8
.
NumberFormatException
- if any of the characters in the specified string is not a hex digit
('0'
to '9'
and 'a'
to
'f'
).public static long parseHexLong(String s, int index) throws IllegalArgumentException, NumberFormatException
s
- the hexadecimal string, cannot be null
.index
- the starting index in the string, must be >= 0.
IllegalArgumentException
- if s == null
|| index < 0
|| s.length()
< index + 16
).
NumberFormatException
- if any of the characters in the specified range of the string is not
a hex digit ('0'
to '9'
and
'a'
to 'f'
).public static long parseHexLong(String s) throws IllegalArgumentException, NumberFormatException
s
- the hexadecimal string, cannot be null
and must have
size 16
(i.e. s.
length()
== 16
).
IllegalArgumentException
- if s == null || s.
length()
!= 16
.
NumberFormatException
- if any of the characters in the specified string is not a hex digit
('0'
to '9'
and 'a'
to
'f'
).
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |