Class Base32Util
java.lang.Object
de.tomatengames.util.Base32Util
Provides methods to convert between a byte array and Base32.
- Since:
- 1.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbase32ToBytes(char[] base32Chars, OutputStream out) Writes the bytes represented by the specified Base32 string into theOutputStream.static byte[]base32ToBytes(String base32) Converts the specified Base32 string into a byte array.static StringbytesToBase32(byte[] bytes, boolean padding) Converts the specified byte array to a Base32 string.static intfromBase32Char(char c) Converts the specified Base32 character to the 5 bit integer it represents.static chartoBase32Char(int value5bit) Converts the specified 5 bit integer to the corresponding Base32 character.
-
Method Details
-
base32ToBytes
Converts the specified Base32 string into a byte array.Does not currently detect invalid padding.
- Parameters:
base32- The Base32 string. Each character my be in lower or upper case. Must not benull.- Returns:
- The bytes represented by the Base32 string. Not
null. - Throws:
IllegalArgumentException- If the string contains non-Base32 characters.
-
base32ToBytes
Writes the bytes represented by the specified Base32 string into theOutputStream.Does not currently detect invalid padding.
- Parameters:
base32Chars- The characters of the Base32 string. Each character my be in lower or upper case. Must not benull.out- The output stream. Must not benull.- Throws:
IOException- If bytes cannot be written to the output stream.IllegalArgumentException- If the string contains non-Base32 characters.
-
bytesToBase32
Converts the specified byte array to a Base32 string.- Parameters:
bytes- The bytes that should be converted. Must not benull.padding- If a padding with'='characters should be added to the end of the Base32 string.- Returns:
- The Base32 string. Not
null.
-
toBase32Char
public static char toBase32Char(int value5bit) Converts the specified 5 bit integer to the corresponding Base32 character.- Parameters:
value5bit- The 5 bit integer.- Returns:
- The Base32 character in upper case.
- Throws:
IllegalArgumentException- If the specified integer is outside the range[0, 0b11111].
-
fromBase32Char
public static int fromBase32Char(char c) Converts the specified Base32 character to the 5 bit integer it represents.- Parameters:
c- The Base32 character. May be in lower or upper case.- Returns:
- The 5 bit integer.
- Throws:
IllegalArgumentException- If the specified character is not a Base32 character.
-