Package com.helger.commons.codec
Class Base32Codec
java.lang.Object
com.helger.commons.codec.Base32Codec
- All Implemented Interfaces:
IByteArrayCodec,IByteArrayDecoder,IByteArrayEncoder,IByteArrayStreamDecoder,IByteArrayStreamEncoder,ICodec<byte[]>,IDecoder<byte[],,byte[]> IEncoder<byte[],byte[]>
Base32 encoder and decoder based on Apache Commons Codec Base32. Defined in
RFC 4648. BASE32 characters are 5 bits in length. They are formed by taking a
block of five octets to form a 40-bit string, which is converted into eight
BASE32 characters.
RFC 3548 and defines only the "regular encoding". RFC 4648 adds the "hex encoding". So when using the "regular encoding" it is compliant to both RFCs.
Source: https://tools.ietf.org/html/rfc4648
Source: https://tools.ietf.org/html/rfc3548
RFC 3548 and defines only the "regular encoding". RFC 4648 adds the "hex encoding". So when using the "regular encoding" it is compliant to both RFCs.
Source: https://tools.ietf.org/html/rfc4648
Source: https://tools.ietf.org/html/rfc3548
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a Base32 codec used for decoding and encoding.Base32Codec(boolean bUseHex) Creates a Base32 codec used for decoding and encoding. -
Method Summary
Modifier and TypeMethodDescriptionvoiddecode(byte[] aEncodedBuffer, int nOfs, int nLen, OutputStream aOS) Decode (part of) a byte array.voidencode(byte[] aDecodedBuffer, int nOfs, int nLen, OutputStream aOS) Encode (part of) a byte array to anOutputStream.intgetMaximumDecodedLength(int nLen) Get the maximum decoded length based on the provided encoded length.intgetMaximumEncodedLength(int nLen) Get the maximum encoded length based on the provided decoded length.bytegetPad()booleanbooleansetAddPaddding(boolean bAddPadding) setPad(byte nPad) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.helger.commons.codec.IByteArrayDecoder
getDecoded, getDecodedMethods inherited from interface com.helger.commons.codec.IByteArrayStreamDecoder
decode, getDecoded, getDecodedAsString, getDecodedAsString, getDecodedAsString, getDecodedAsStringMethods inherited from interface com.helger.commons.codec.IByteArrayStreamEncoder
encode, getEncoded, getEncoded, getEncoded, getEncodedAsString, getEncodedAsString, getEncodedAsString
-
Constructor Details
-
Base32Codec
public Base32Codec()Creates a Base32 codec used for decoding and encoding. -
Base32Codec
public Base32Codec(boolean bUseHex) Creates a Base32 codec used for decoding and encoding.- Parameters:
bUseHex-trueto use hex encoding,falseto use regular encoding.
-
-
Method Details
-
isHexEncoding
public boolean isHexEncoding() -
getPad
public byte getPad() -
setPad
-
isAddPadding
public boolean isAddPadding() -
setAddPaddding
-
getMaximumEncodedLength
public int getMaximumEncodedLength(int nLen) Description copied from interface:IByteArrayEncoderGet the maximum encoded length based on the provided decoded length. This is purely for performance reasons. The name of the method would be better called "getMaximumEncodedLength".- Specified by:
getMaximumEncodedLengthin interfaceIByteArrayEncoder- Specified by:
getMaximumEncodedLengthin interfaceIByteArrayStreamEncoder- Parameters:
nLen- The decoded length. Always ≥ 0.- Returns:
- The maximum encoded length. Always ≥ 0.
-
encode
public void encode(@Nullable byte[] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull @WillNotClose OutputStream aOS) Description copied from interface:IByteArrayStreamEncoderEncode (part of) a byte array to anOutputStream.- Specified by:
encodein interfaceIByteArrayStreamEncoder- Parameters:
aDecodedBuffer- The byte array to be encoded. May benull.nOfs- Offset into the byte array to start from.nLen- Number of bytes starting from offset to consider.aOS- The output stream to write to. May not benulland is NOT closed afterwards!
-
getMaximumDecodedLength
public int getMaximumDecodedLength(int nLen) Description copied from interface:IByteArrayDecoderGet the maximum decoded length based on the provided encoded length. This is purely for performance reasons.- Specified by:
getMaximumDecodedLengthin interfaceIByteArrayDecoder- Parameters:
nLen- The encoded length. Always ≥ 0.- Returns:
- The maximum decoded length. Always ≥ 0.
-
decode
public void decode(@Nullable byte[] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull @WillNotClose OutputStream aOS) Description copied from interface:IByteArrayStreamDecoderDecode (part of) a byte array.- Specified by:
decodein interfaceIByteArrayStreamDecoder- Parameters:
aEncodedBuffer- The byte array to be decoded. May benull.nOfs- Offset into the byte array to start from.nLen- Number of bytes starting from offset to consider.aOS- The output stream to write to. May not benulland is NOT closed afterwards!
-