Package com.helger.commons.codec
Class Base64Codec
java.lang.Object
com.helger.commons.codec.Base64Codec
- All Implemented Interfaces:
IByteArrayCodec,IByteArrayDecoder,IByteArrayEncoder,IByteArrayStreamDecoder,IByteArrayStreamEncoder,ICodec<byte[]>,IDecoder<byte[],,byte[]> IEncoder<byte[],byte[]>
Encoder and decoder for Base64
- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Base64InputStreamprotected Base64OutputStreamvoiddecode(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.byte[]getDecoded(byte[] aEncodedBuffer, int nOfs, int nLen) Decode a byte array.byte[]getEncoded(byte[] aDecodedBuffer, int nOfs, int nLen) Encode a byte array.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.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, getDecodedAsString, getDecodedAsString, getDecodedAsString, getDecodedAsStringMethods inherited from interface com.helger.commons.codec.IByteArrayStreamEncoder
encode, getEncoded, getEncoded, getEncodedAsString, getEncodedAsString, getEncodedAsString
-
Constructor Details
-
Base64Codec
public Base64Codec()
-
-
Method Details
-
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.
-
createBase64OutputStream
@Nonnull @OverrideOnDemand protected Base64OutputStream createBase64OutputStream(@Nonnull @WillNotClose OutputStream aOS) -
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!
-
getEncoded
@Nullable @ReturnsMutableCopy public byte[] getEncoded(@Nullable byte[] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen) Description copied from interface:IByteArrayStreamEncoderEncode a byte array.- Specified by:
getEncodedin interfaceIByteArrayEncoder- Specified by:
getEncodedin 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.- Returns:
- The encoded byte array or
nullif the parameter wasnull.
-
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.
-
createBase64InputStream
@Nonnull @OverrideOnDemand protected Base64InputStream createBase64InputStream(@Nonnull NonBlockingByteArrayInputStream aBAIS) -
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!
-
getDecoded
@Nullable @ReturnsMutableCopy public byte[] getDecoded(@Nullable byte[] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen) Description copied from interface:IByteArrayStreamDecoderDecode a byte array.- Specified by:
getDecodedin interfaceIByteArrayDecoder- Specified by:
getDecodedin 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.- Returns:
- The decoded byte array or
nullif the parameter wasnull.
-