Package com.helger.base.codec.base64
Class Base64Codec
java.lang.Object
com.helger.base.codec.base64.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 @NonNull Base64InputStreamcreateBase64InputStream(@NonNull NonBlockingByteArrayInputStream aBAIS) protected @NonNull Base64OutputStreamcreateBase64OutputStream(@NonNull OutputStream aOS) voiddecode(byte @Nullable [] aEncodedBuffer, int nOfs, int nLen, @NonNull OutputStream aOS) Decode the passed Base64 encoded buffer and write the decoded bytes to the output stream.voidencode(byte @Nullable [] aDecodedBuffer, int nOfs, int nLen, @NonNull OutputStream aOS) Encode the passed decoded buffer to Base64 and write it to the output stream.byte @Nullable []getDecoded(byte @Nullable [] aEncodedBuffer, int nOfs, int nLen) Decode a byte array.byte @Nullable []getEncoded(byte @Nullable [] 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.base.codec.IByteArrayDecoder
getDecoded, getDecodedMethods inherited from interface com.helger.base.codec.IByteArrayStreamDecoder
decode, getDecodedAsString, getDecodedAsString, getDecodedAsString, getDecodedAsStringMethods inherited from interface com.helger.base.codec.IByteArrayStreamEncoder
encode, getEncoded, getEncoded, getEncodedAsString, getEncodedAsString, getEncodedAsString
-
Constructor Details
-
Base64Codec
public Base64Codec()Constructor.
-
-
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
@OverrideOnDemand protected @NonNull Base64OutputStream createBase64OutputStream(@WillNotClose @NonNull OutputStream aOS) -
encode
public void encode(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS) Encode the passed decoded buffer to Base64 and write it to the output stream.- Specified by:
encodein interfaceIByteArrayStreamEncoder- Parameters:
aDecodedBuffer- The buffer to be encoded. May benull.nOfs- The offset in the buffer to start encoding from.nLen- The number of bytes to encode.aOS- The output stream to write the encoded data to. May not benull.
-
getEncoded
@ReturnsMutableCopy public byte @Nullable [] getEncoded(byte @Nullable [] 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
@OverrideOnDemand protected @NonNull Base64InputStream createBase64InputStream(@NonNull NonBlockingByteArrayInputStream aBAIS) -
decode
public void decode(byte @Nullable [] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS) Decode the passed Base64 encoded buffer and write the decoded bytes to the output stream.- Specified by:
decodein interfaceIByteArrayStreamDecoder- Parameters:
aEncodedBuffer- The Base64 encoded buffer to be decoded. May benull.nOfs- The offset in the buffer to start decoding from.nLen- The number of bytes to decode.aOS- The output stream to write the decoded data to. May not benull.
-
getDecoded
@ReturnsMutableCopy public byte @Nullable [] getDecoded(byte @Nullable [] 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.
-