Package org.dellroad.stuff.string
Class ByteArrayEncoder
java.lang.Object
org.dellroad.stuff.string.ByteArrayEncoder
Encodes
byte[]
arrays to and from hexadecimal strings.-
Method Summary
-
Method Details
-
encode
- Parameters:
array
- byte array, ornull
- Returns:
- hexadecimal string (or
null
ifarray
wasnull
)
-
encode
Encode abyte[]
array as aString
.- Parameters:
array
- byte array, ornull
off
- offset into the arraylen
- number of bytes to convert- Returns:
- hexadecimal string (or
null
ifarray
wasnull
) - Throws:
IndexOutOfBoundsException
- if array bounds are exceededIllegalArgumentException
- iflen
is greater thanInteger.MAX_VALUE / 2
-
decode
Decode aString
back into abyte[]
array. Any extra whitespace in the string is ignored.- Parameters:
text
- string previously encoded byencode(byte[])
, ornull
- Returns:
- original
byte[]
array (ornull
iftext
wasnull
) - Throws:
IllegalArgumentException
- if any invalid non-whitespace characters are seen, or the number of hex digits is odd
-