Class Convert
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 StringbytesToHexStr(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 StringgetMessages(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 inthexToNibble(char hexchr) Returns the nibble (4-bits) of the supplied hexadecimal char.static StringReturns 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- ifbytesisnull.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- ifbytesisnull.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- ifbytesisnull.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- ifbytesisnull.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- ifstrisnull.
-
getMessages
-
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- ifbytesisnull.
-
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- ifbytesisnull.
-
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- ifhexstrisnull.IllegalArgumentException- ifhexstris 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
hexchrchar. - Throws:
IllegalArgumentException- ifhexchris invalid.
-