Class Conversion
java.lang.Object
com.saperion.common.lang.conversion.Conversion
Utility class for conversion.
Supports the following conversions typically in both directions:
- hex-
char
<->byte
char[]
of hex-char
<->byte[]
(with optional header and spacing)- base64-
char
<->byte
char[]
of base64-char
<->byte[]
InputStream
->byte[]
(only one way; to implement the inverse direction simply construct aByteArrayInputStream
)Serializable
<->byte[]
Collection
<String
> <->String
(with separator and correct escaping)
All these methods are optimized for speed! Do not change them without controlling their performance behavior!
Many methods return a char[]
instead of a String
as some might expect. This is done out of
performance considerations too. If one really needs a String
it can be constructed by
String.valueOf(char[])
. But in many cases the converted result will not be used directly, but instead will be
copied into a StringBuilder
/StringBuffer
or some kind of Writer
. In such cases one should use
the char[]
directly and avoid an intermediate String
.
- Author:
- agz
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte
convertBase64CharacterToByte
(char base64Character) Converts the specified a base64 character to a byte value.static byte[]
convertBase64ToByteArray
(char[] arBase64Chars) Parses the specifiedchar[]
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
.static byte[]
convertBase64ToByteArray
(char[] arBase64Chars, int beginIndex, int endIndex) Parses the specifiedchar[]
section from the specified begin index to the specified end index- 1
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
.static byte[]
convertBase64ToByteArray
(String base64String) Parses the specifiedString
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
.static byte[]
convertBase64ToByteArray
(String base64String, int beginIndex, int endIndex) Parses the specifiedString
section from the specified begin index to the specified end index- 1
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
.static char[]
convertByteArrayToBase64
(byte[] arBytes) Returns achar[]
containing a base64 encoding that represents the bytes of the specifiedbyte[]
.static char[]
convertByteArrayToBase64
(byte[] arBytes, int beginIndex, int endIndex) Returns achar[]
containing a base64 encoding that represents the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
.static char[]
convertByteArrayToHexDigits
(byte[] arBytes) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, int beginIndex, int endIndex) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, int beginIndex, int endIndex, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally separated at the specified interval of bytes by the specified separator character.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, int beginIndex, int endIndex, String header) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally preceded by the specified header string.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, int beginIndex, int endIndex, String header, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, String header) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally preceded by the specified header string.static char[]
convertByteArrayToHexDigits
(byte[] arBytes, String header, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string.static Serializable
convertByteArrayToSerializable
(byte[] arBytes) Converts the specifiedbyte[]
into aSerializable
using standard deserialization.static byte[]
convertHexDigitsToByteArray
(char[] arHexChars) Parses the specifiedchar[]
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte[]
convertHexDigitsToByteArray
(char[] arHexChars, int beginIndex) Parses the specifiedchar[]
section from the specified begin index to its end assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte[]
convertHexDigitsToByteArray
(char[] arHexChars, int beginIndex, int endIndex) Parses the specifiedchar[]
section from the specified begin index to the specified end index- 1
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte[]
convertHexDigitsToByteArray
(String hexString) Parses the specifiedString
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte[]
convertHexDigitsToByteArray
(String hexString, int beginIndex) Parses the specifiedString
section from the specified begin index to its end assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte[]
convertHexDigitsToByteArray
(String hexString, int beginIndex, int endIndex) Parses the specifiedString
section from the specified begin index to the specified end index- 1
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters.static byte
convertHexDigitToByte
(char digit) Converts the specified a hexadecimal digit character to a byte value.static byte[]
convertInputStreamToByteArray
(InputStream inputStream) Deprecated.static char
convertIntToBase64Character
(int i) Converts the specified integer value to a base64 character.static char
convertIntToHexDigit
(int i) Converts the specified integer value to a hexadecimal digit character.static byte[]
convertSerializableToByteArray
(Serializable serializable, int sizeGuess) Converts the specifiedSerializable
into abyte[]
using standard serialization.static String
convertStringCollectionToString
(Collection<String> colStrings, char separator, char escape, String nullString) Converts the specified collection of strings to a string using the specified separator, escape character and string fornull
-elements.convertStringToStringList
(String string, char separator, char escape, String nullString) Converts the specified string to a list of strings using the specified separator, escape character and string fornull
-elements.
-
Method Details
-
convertIntToHexDigit
public static char convertIntToHexDigit(int i) Converts the specified integer value to a hexadecimal digit character. Letters are in upper case always. Returns0xffff
if the specified integer value is less than0
or greater than15
. Returns char'0'-'9'
(0x0030-0x0039
) if the specified integer is in the range0-9
. Returns char'A'-'F'
(0x0061-0x0066
) if the specified integer is in the range10-15
.- Parameters:
i
- integer value to convert- Returns:
- hexadecimal digit character for the specified integer value or
0xffff
- See Also:
-
convertHexDigitToByte
public static byte convertHexDigitToByte(char digit) Converts the specified a hexadecimal digit character to a byte value. Letters may be upper or lower case. Returns-1
if the specified character is not a hexadecimal digit. Returns0-9
if the specified character is char'0'-'9'
(0x0030-0x0039
). Returns10-15
if the specified character is char'A'-'F'
(0x0061-0x0066
). Returns10-15
if the specified character is char'a'-'f'
(0x0041-0x0046
).- Parameters:
digit
- hexadecimal digit character to convert- Returns:
- byte value of the specified hexadecimal digit character or
-1
- See Also:
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, int beginIndex, int endIndex, String header, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specifiedbyte[]
or equal to its length. The specified begin index must not be greater than the specified end index. The specified header is optional (may benull
, may be an empty string). The specified block size must not be less than0
. If a value of0
is specified no separation is done.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsbeginIndex
- begin index of the section of the specifiedbyte[]
to convertendIndex
- end index of the section of the specifiedbyte[]
to convertheader
- string to copy at the start of the resultingchar[]
ornull
blockSeparator
- separator character to add every 'blockSize' bytes to the resultingchar[]
blockSize
- interval (in bytes) to add the specified separator character to the resultingchar[]
or0
if no separation should be done.- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, int beginIndex, int endIndex, String header) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally preceded by the specified header string. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. Throws anIndexOutOfBoundsException
if the specified begin index is not inside the specifiedbyte[]
or the specified end index is not inside the specifiedbyte[]
or equal to its length. The specified begin index must not be greater than the specified end index. The specified header is optional (may benull
, may be an empty string).- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsbeginIndex
- begin index of the section of the specifiedbyte[]
to convertendIndex
- end index of the section of the specifiedbyte[]
to convertheader
- string to copy at the start of the resultingchar[]
ornull
- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section optionally preceded by the specified header string - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, int beginIndex, int endIndex, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
optionally separated at the specified interval of bytes by the specified separator character. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. Throws anIndexOutOfBoundsException
if the specified begin index is not inside the specifiedbyte[]
or the specified end index is not inside the specifiedbyte[]
or equal to its length. The specified begin index must not be greater than the specified end index. The specified block size must not be less than0
. If a value of0
is specified no separation is done.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsbeginIndex
- begin index of the section of the specifiedbyte[]
to convertendIndex
- end index of the section of the specifiedbyte[]
to convertblockSeparator
- separator character to add every 'blockSize' bytes to the resultingchar[]
blockSize
- interval (in bytes) to add the specified separator character to the resultingchar[]
or0
if no separation should be done.- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section optionally separated at the specified interval of bytes by the specified separator character - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, int beginIndex, int endIndex) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. Throws anIndexOutOfBoundsException
if the specified begin index is not inside the specifiedbyte[]
or the specified end index is not inside the specifiedbyte[]
or equal to its length. The specified begin index must not be greater than the specified end index.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsbeginIndex
- begin index of the section of the specifiedbyte[]
to convertendIndex
- end index of the section of the specifiedbyte[]
to convert- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
section - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, String header, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. The specified header is optional (may benull
, may be an empty string). The specified block size must not be less than0
. If a value of0
is specified no separation is done.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsheader
- string to copy at the start of the resultingchar[]
ornull
blockSeparator
- separator character to add every 'blockSize' bytes to the resultingchar[]
blockSize
- interval (in bytes) to add the specified separator character to the resultingchar[]
or0
if no separation should be done.- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character and optionally preceded by the specified header string - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes, char blockSeparator, int blockSize) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. The specified block size must not be less than0
. If a value of0
is specified no separation is done.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsblockSeparator
- separator character to add every 'blockSize' bytes to the resultingchar[]
blockSize
- interval (in bytes) to add the specified separator character to the resultingchar[]
or0
if no separation should be done.- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally separated at the specified interval of bytes by the specified separator character - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], String)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally preceded by the specified header string. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. The specified header is optional (may benull
, may be an empty string).- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digitsheader
- string to copy at the start of the resultingchar[]
ornull
- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
optionally preceded by the specified header string - See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[])
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertByteArrayToHexDigits
public static char[] convertByteArrayToHexDigits(byte[] arBytes) Returns achar[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
. The resultingchar[]
has exactly the necessary size (twice the size of the specifiedbyte[]
). The specifiedbyte[]
must not benull
.- Parameters:
arBytes
-byte[]
to convert to pairwise hexadecimal digits- Returns:
- new
char[]
containing pairwise hexadecimal digits that represent the bytes of the specifiedbyte[]
- See Also:
-
convertByteArrayToHexDigits(byte[], int, int, String, char, int)
convertByteArrayToHexDigits(byte[], int, int, String)
convertByteArrayToHexDigits(byte[], int, int, char, int)
convertByteArrayToHexDigits(byte[], int, int)
convertByteArrayToHexDigits(byte[], String, char, int)
convertByteArrayToHexDigits(byte[], char, int)
convertByteArrayToHexDigits(byte[], String)
convertHexDigitsToByteArray(String, int, int)
convertHexDigitsToByteArray(char[], int, int)
-
convertHexDigitsToByteArray
Parses the specifiedString
section from the specified begin index to the specified end index- 1
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specified string isnull
. Returns an emptybyte[]
if the specified string is empty. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specified string or itsString.length()
. The specified begin index must not be greater than the specified end index. The specified string section must not contain an impair block of hexadecimal digits.- Parameters:
hexString
- string containing pairwise hexadecimal digits to convertbeginIndex
- begin index of the section of the specified string to convertendIndex
- end index of the section of the specified string to convert- Returns:
- new
byte[]
containing the parsed content of the specified string section - See Also:
-
convertHexDigitsToByteArray
Parses the specifiedString
section from the specified begin index to its end assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specified string isnull
. Returns an emptybyte[]
if the specified string is empty. Throws anIndexOutOfBoundsException
if the specified begin index is not inside the specified string. The specified string section must not contain an impair block of hexadecimal digits.- Parameters:
hexString
- string containing pairwise hexadecimal digits to convertbeginIndex
- begin index of the section of the specified string to convert- Returns:
- new
byte[]
containing the parsed content of the specified string section - See Also:
-
convertHexDigitsToByteArray
Parses the specifiedString
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specified string isnull
. Returns an emptybyte[]
if the specified string is empty. The specified string must not contain an impair block of hexadecimal digits.- Parameters:
hexString
- string containing pairwise hexadecimal digits to convert- Returns:
- new
byte[]
containing the parsed content of the specified string section - See Also:
-
convertHexDigitsToByteArray
public static byte[] convertHexDigitsToByteArray(char[] arHexChars, int beginIndex, int endIndex) Parses the specifiedchar[]
section from the specified begin index to the specified end index- 1
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specifiedchar[]
isnull
. Returns an emptybyte[]
if the specifiedchar[]
is empty. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specifiedchar[]
or equal to its length. The specified begin index must not be greater than the specified end index. The specifiedchar[]
section must not contain an impair block of hexadecimal digits.- Parameters:
arHexChars
-char[]
containing pairwise hexadecimal digits to convertbeginIndex
- begin index of the section of the specifiedchar[]
to convertendIndex
- end index of the section of the specifiedchar[]
to convert- Returns:
- new
byte[]
containing the parsed content of the specifiedchar[]
section - See Also:
-
convertHexDigitsToByteArray
public static byte[] convertHexDigitsToByteArray(char[] arHexChars, int beginIndex) Parses the specifiedchar[]
section from the specified begin index to its end assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specifiedchar[]
isnull
. Returns an emptybyte[]
if the specifiedchar[]
is empty. Throws anIndexOutOfBoundsException
if the specified begin index is not inside the specifiedchar[]
. The specifiedchar[]
section must not contain an impair block of hexadecimal digits.- Parameters:
arHexChars
-char[]
containing pairwise hexadecimal digits to convertbeginIndex
- begin index of the section of the specifiedchar[]
to convert- Returns:
- new
byte[]
containing the parsed content of the specifiedchar[]
section - See Also:
-
convertHexDigitsToByteArray
public static byte[] convertHexDigitsToByteArray(char[] arHexChars) Parses the specifiedchar[]
assuming that it consists of pairs of hexadecimal digits optionally separated by other characters. Converts these pairs of hexadecimal digits to bytes and returns a newbyte[]
containing these bytes. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specifiedchar[]
isnull
. Returns an emptybyte[]
if the specifiedchar[]
is empty. The specifiedchar[]
must not contain an impair block of hexadecimal digits.- Parameters:
arHexChars
-char[]
containing pairwise hexadecimal digits to convert- Returns:
- new
byte[]
containing the parsed content of the specifiedchar[]
- See Also:
-
convertIntToBase64Character
public static char convertIntToBase64Character(int i) Converts the specified integer value to a base64 character. Returns0xffff
if the specified integer value is less than0
or greater than63
.- Parameters:
i
- integer value to convert- Returns:
- base64 character for the specified integer value or
0xffff
- See Also:
-
convertBase64CharacterToByte
public static byte convertBase64CharacterToByte(char base64Character) Converts the specified a base64 character to a byte value. Returns-1
if the specified character is not a base64 character.- Parameters:
base64Character
- base64 character to convert- Returns:
- byte value of the specified base64 character or
-1
- See Also:
-
convertByteArrayToBase64
public static char[] convertByteArrayToBase64(byte[] arBytes, int beginIndex, int endIndex) Returns achar[]
containing a base64 encoding that represents the bytes of the specifiedbyte[]
section from the specified begin index to the specified end index- 1
. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specifiedbyte[]
or equal to its length. The specified begin index must not be greater than the specified end index.- Parameters:
arBytes
-byte[]
to convert to base64 encoded charactersbeginIndex
- begin index of the section of the specifiedbyte[]
to convertendIndex
- end index of the section of the specifiedbyte[]
to convert- Returns:
- new
char[]
containing a base64 encoding that represent the bytes of the specifiedbyte[]
section - See Also:
-
convertByteArrayToBase64
public static char[] convertByteArrayToBase64(byte[] arBytes) Returns achar[]
containing a base64 encoding that represents the bytes of the specifiedbyte[]
. The resultingchar[]
has exactly the necessary size. The specifiedbyte[]
must not benull
.- Parameters:
arBytes
-byte[]
to convert to base64 encoded characters- Returns:
- new
char[]
containing a base64 encoding that represent the bytes of the specifiedbyte[]
- See Also:
-
convertBase64ToByteArray
Parses the specifiedString
section from the specified begin index to the specified end index- 1
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specified string isnull
. Returns an emptybyte[]
if the specified string section is empty. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specified string or itsString.length()
. The specified begin index must not be greater than the specified end index. The specified string sections size must be a multiple of 4.- Parameters:
base64String
- string containing base64 encoded quadruples of characters to convertbeginIndex
- begin index of the section of the specified string to convertendIndex
- end index of the section of the specified string to convert- Returns:
- new
byte[]
containing the parsed content of the specified string section - See Also:
-
convertBase64ToByteArray
Parses the specifiedString
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specified string isnull
. Returns an emptybyte[]
if the specified string is empty. The specified string size must be a multiple of 4.- Parameters:
base64String
- string containing base64 encoded quadruples of characters to convert- Returns:
- new
byte[]
containing the parsed content of the specified string - See Also:
-
convertBase64ToByteArray
public static byte[] convertBase64ToByteArray(char[] arBase64Chars, int beginIndex, int endIndex) Parses the specifiedchar[]
section from the specified begin index to the specified end index- 1
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specifiedchar[]
isnull
. Returns an emptybyte[]
if the specifiedchar[]
is empty. Throws anIndexOutOfBoundsException
if the specified begin or end index is not inside the specifiedchar[]
or equal to its length. The specified begin index must not be greater than the specified end index. The specifiedchar[]
sections size must be a multiple of 4.- Parameters:
arBase64Chars
-char[]
containing base64 encoded quadruples of characters to convertbeginIndex
- begin index of the section of the specifiedchar[]
to convertendIndex
- end index of the section of the specifiedchar[]
to convert- Returns:
- new
byte[]
containing the parsed content of the specifiedchar[]
section - See Also:
-
convertBase64ToByteArray
public static byte[] convertBase64ToByteArray(char[] arBase64Chars) Parses the specifiedchar[]
assuming that it consists of base64 encoded quadruples of characters and converts it to abyte[]
. The resultingbyte[]
has exactly the necessary size. Returnsnull
if the specifiedchar[]
isnull
. Returns an emptybyte[]
if the specifiedchar[]
is empty. The specifiedchar[]
size must be a multiple of 4.- Parameters:
arBase64Chars
-char[]
containing base64 encoded quadruples of characters to convert- Returns:
- new
byte[]
containing the parsed content of the specifiedchar[]
- See Also:
-
convertInputStreamToByteArray
@Deprecated public static byte[] convertInputStreamToByteArray(InputStream inputStream) throws IOException Deprecated.Returns the content of the specifiedInputStream
as abyte[]
, which has exactly the size of the content. The specifiedInputStream
must not benull
.- Parameters:
inputStream
-InputStream
to convert into abyte[]
- Returns:
byte[]
with the content of the specifiedInputStream
- Throws:
IOException
- on errors reading the inputStream
-
convertSerializableToByteArray
public static byte[] convertSerializableToByteArray(Serializable serializable, int sizeGuess) throws IOException Converts the specifiedSerializable
into abyte[]
using standard serialization. The specified size guess need not be exact, i.e. in can be too small or too large. The returnedbyte[]
has always exactly the necessary size. The parameter is for optimization of memory allocation only and a good guess should be provided by the caller. The specified size guess must be greater than0
.- Parameters:
serializable
- theSerializable
to convertsizeGuess
- size guess- Returns:
- a
byte[]
containing the convertedSerializable
- Throws:
IOException
- on errors during serialization
-
convertByteArrayToSerializable
public static Serializable convertByteArrayToSerializable(byte[] arBytes) throws IOException, ClassNotFoundException Converts the specifiedbyte[]
into aSerializable
using standard deserialization. The specifiedbyte[]
must not benull
.- Parameters:
arBytes
-byte[]
to convert- Returns:
- the converted
Serializable
- Throws:
IOException
- on errors during deserializationClassNotFoundException
- on errors during deserialization
-
convertStringCollectionToString
public static String convertStringCollectionToString(Collection<String> colStrings, char separator, char escape, String nullString) Converts the specified collection of strings to a string using the specified separator, escape character and string fornull
-elements. All strings created with this method can be converted back withconvertStringToStringList(String, char, char, String)
, so that the resulting list will contain equal strings to the original collection. This method is intended for data conversion and therefore needs to use escape sequences to create a bijective format. For a non-escaping method seeStrings.format(Collection, String, String)
, f.e. to create a human-readable simple output. If the specified collection isnull
, thennull
will be returned. If the specified collection is empty, an empty string will be returned. The specified separator and escape characters must be different. The specified string fornull
-elements must not benull
or empty and must not start with the specified escape character.- Parameters:
colStrings
- collection of strings to convertseparator
- separator character, a usual value is';'
escape
- escape character, a usual value is'/'
nullString
- string fornull
-elements, a usual value is"<null>"
- Returns:
- string
- See Also:
-
convertStringToStringList
public static List<String> convertStringToStringList(String string, char separator, char escape, String nullString) Converts the specified string to a list of strings using the specified separator, escape character and string fornull
-elements. All strings created withconvertStringCollectionToString(Collection, char, char, String)
can be converted back with this method, so that the resulting list will contain equal strings to the original collection. If the specified string isnull
, thennull
will be returned. If the specified string is empty, an empty list will be returned. The specified separator and escape characters must be different. The specified string fornull
-elements must not benull
or empty and must not start with the specified escape character.- Parameters:
string
- string to convertseparator
- separator character, a usual value is';'
escape
- escape character, a usual value is'/'
nullString
- string fornull
-elements, a usual value is"<null>"
- Returns:
- list of strings
- Throws:
IllegalStateException
- on format errors in the specified string- See Also:
-
Streams.convertInputStreamToByteArray(java.io.InputStream)
instead