java.lang.Object
cl.netswitch.lib.util.Convert
Provides static utility methods that perform general conversions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
bytesToHexBytes
(byte[] bytes) Returns the hexadecimal digits representing the supplied byte array.static String
bytesToHexStr
(byte[] bytes) Returns an hexadecimal string representing the supplied byte array.static byte[]
compressBytes
(byte[] bytes) Returns a compressed representation of the supplied bytes.static byte[]
compressBytes
(byte[] bytes, int offset, int length) Returns a compressed representation of the specified byte range.static String
getMessages
(Throwable thrown) Returns the string representation of the supplied throwable.static byte[]
hexToBytes
(String hexstr) Returns the byte array represented by supplied hexadecimal string.static int
hexToNibble
(char hexchr) Returns the nibble (4-bits) of the supplied hexadecimal char.static String
Returns a copy of a string with trailing spaces ' ' removed.static byte[]
uncompressBytes
(byte[] bytes) Returns an uncompressed representation of the supplied bytes.static byte[]
uncompressBytes
(byte[] bytes, int offset, int length) Returns an uncompressed representation of the specified byte range.
-
Method Details
-
uncompressBytes
public static byte[] uncompressBytes(byte[] bytes) Returns an uncompressed representation of the supplied bytes.- Parameters:
bytes
- the bytes to be uncompressed.- Returns:
- an uncompressed representation of the supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.
-
uncompressBytes
public static byte[] uncompressBytes(byte[] bytes, int offset, int length) Returns an uncompressed representation of the specified byte range.- Parameters:
bytes
- the bytes to be uncompressed.offset
- the index of the first byte to uncompress.length
- the total number of bytes to uncompress.- Returns:
- an uncompressed representation of the specified byte range.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.
-
compressBytes
public static byte[] compressBytes(byte[] bytes) Returns a compressed representation of the supplied bytes.- Parameters:
bytes
- the bytes to be compressed.- Returns:
- a compressed representation of the supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.
-
compressBytes
public static byte[] compressBytes(byte[] bytes, int offset, int length) Returns a compressed representation of the specified byte range.- Parameters:
bytes
- the bytes to be compressed.offset
- the index of the first byte to compress.length
- the total number of bytes to compress.- Returns:
- a compressed representation of the specified byte range.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.
-
rightTrim
Returns a copy of a string with trailing spaces ' ' removed.- Parameters:
str
- the string to be right-trimmed.- Returns:
- a copy of a string with trailing spaces ' ' removed.
- Throws:
NullPointerException
- ifstr
isnull
.
-
getMessages
Returns the string representation of the supplied throwable.- Parameters:
thrown
- the throwable to convert to a string (can be null).- Returns:
- the string representation of the supplied throwable.
-
bytesToHexStr
Returns an hexadecimal string representing the supplied byte array.- Parameters:
bytes
- the bytes to convert to an hexadecimal representation.- Returns:
- an hexadecimal string representation of supplied byte array.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
bytesToHexBytes
public static byte[] bytesToHexBytes(byte[] bytes) Returns the hexadecimal digits representing the supplied byte array.- Parameters:
bytes
- the bytes to be converted to hexadecimal digits.- Returns:
- the hexadecimal digits representing the supplied byte array.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
hexToBytes
Returns the byte array represented by supplied hexadecimal string.- Parameters:
hexstr
- the hexadecimal string to be converted.- Returns:
- the byte array represented by supplied hexadecimal string.
- Throws:
NullPointerException
- ifhexstr
isnull
.IllegalArgumentException
- ifhexstr
is invalid.
-
hexToNibble
public static int hexToNibble(char hexchr) Returns the nibble (4-bits) of the supplied hexadecimal char.- Parameters:
hexchr
- the hexadecimal character.- Returns:
- the nibble (4-bits) of the supplied
hexchr
char. - Throws:
IllegalArgumentException
- ifhexchr
is invalid.
-