Home All Groups
commons-codec / org / apache / commons / codec / binary / Base32.html /
org.apache.commons.codec.binary

Class Base32

  • All Implemented Interfaces:
    BinaryDecoder, BinaryEncoder, Decoder, Encoder

    public class Base32
    extends BaseNCodec
    Provides Base32 encoding and decoding as defined by RFC 4648.

    The class can be parameterized in the following manner with various constructors:

    • Whether to use the "base32hex" variant instead of the default "base32"
    • Line length: Default 76. Line length that aren't multiples of 8 will still essentially end up being multiples of 8 in the encoded data.
    • Line separator: Default is CRLF ("\r\n")

    This class operates directly on byte streams, and not character streams.

    This class is thread-safe.

    Since:
    1.5
    Version:
    $Id: Base32.java 1488493 2013-06-01 08:43:58Z sebb $
    See Also:
    RFC 4648
    • Constructor Detail

      • Base32

        public Base32()
        Creates a Base32 codec used for decoding and encoding.

        When encoding the line length is 0 (no chunking).

      • Base32

        public Base32(boolean useHex)
        Creates a Base32 codec used for decoding and encoding.

        When encoding the line length is 0 (no chunking).

        Parameters:
        useHex - if true then use Base32 Hex alphabet
      • Base32

        public Base32(int lineLength)
        Creates a Base32 codec used for decoding and encoding.

        When encoding the line length is given in the constructor, the line separator is CRLF.

        Parameters:
        lineLength - Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
      • Base32

        public Base32(int lineLength,
              byte[] lineSeparator)
        Creates a Base32 codec used for decoding and encoding.

        When encoding the line length and line separator are given in the constructor.

        Line lengths that aren't multiples of 8 will still essentially end up being multiples of 8 in the encoded data.

        Parameters:
        lineLength - Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
        lineSeparator - Each line of encoded data will end with this sequence of bytes.
        Throws:
        IllegalArgumentException - The provided lineSeparator included some Base32 characters. That's not going to work!
      • Base32

        public Base32(int lineLength,
              byte[] lineSeparator,
              boolean useHex)
        Creates a Base32 / Base32 Hex codec used for decoding and encoding.

        When encoding the line length and line separator are given in the constructor.

        Line lengths that aren't multiples of 8 will still essentially end up being multiples of 8 in the encoded data.

        Parameters:
        lineLength - Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 8). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding.
        lineSeparator - Each line of encoded data will end with this sequence of bytes.
        useHex - if true, then use Base32 Hex alphabet, otherwise use Base32 alphabet
        Throws:
        IllegalArgumentException - The provided lineSeparator included some Base32 characters. That's not going to work! Or the lineLength > 0 and lineSeparator is null.
    • Method Detail

      • isInAlphabet

        public boolean isInAlphabet(byte octet)
        Returns whether or not the octet is in the Base32 alphabet.
        Specified by:
        isInAlphabet in class  BaseNCodec
        Parameters:
        octet - The value to test
        Returns:
        true if the value is defined in the the Base32 alphabet false otherwise.

Copyright © 2002–2013 The Apache Software Foundation. All rights reserved.