Class Base32Util

java.lang.Object
de.tomatengames.util.Base32Util

public class Base32Util extends Object
Provides methods to convert between a byte array and Base32.
Since:
1.3
  • Method Details

    • base32ToBytes

      public static byte[] base32ToBytes(String base32)
      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 be null.
      Returns:
      The bytes represented by the Base32 string. Not null.
      Throws:
      IllegalArgumentException - If the string contains non-Base32 characters.
    • base32ToBytes

      public static void base32ToBytes(char[] base32Chars, OutputStream out) throws IOException
      Writes the bytes represented by the specified Base32 string into the OutputStream.

      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 be null.
      out - The output stream. Must not be null.
      Throws:
      IOException - If bytes cannot be written to the output stream.
      IllegalArgumentException - If the string contains non-Base32 characters.
    • bytesToBase32

      public static String bytesToBase32(byte[] bytes, boolean padding)
      Converts the specified byte array to a Base32 string.
      Parameters:
      bytes - The bytes that should be converted. Must not be null.
      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.