Package com.helger.commons.codec
Interface IByteArrayStreamEncoder
- All Superinterfaces:
IByteArrayEncoder,IEncoder<byte[],byte[]>
- All Known Subinterfaces:
IByteArrayCodec
- All Known Implementing Classes:
Base16Codec,Base32Codec,Base64Codec,FlateCodec,GZIPCodec,IdentityByteArrayCodec,LZWCodec,QuotedPrintableCodec,URLCodec
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Interface for a single encoder of bytes, based on streams.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionvoidencode(byte[] aDecodedBuffer, int nOfs, int nLen, OutputStream aOS) Encode (part of) a byte array to anOutputStream.default voidencode(byte[] aDecodedBuffer, OutputStream aOS) Encode a byte array to anOutputStream.default byte[]getEncoded(byte[] aDecodedBuffer) Encode a byte array.default byte[]getEncoded(byte[] aDecodedBuffer, int nOfs, int nLen) Encode a byte array.default byte[]getEncoded(String sDecoded, Charset aCharset) Encode the passed string.default StringgetEncodedAsString(byte[] aDecodedBuf, int nOfs, int nLen, Charset aCharset) default StringgetEncodedAsString(byte[] aDecodedBuf, Charset aCharset) default StringgetEncodedAsString(String sDecoded, Charset aCharset) Encode the passed string and return the result as a String.default intgetMaximumEncodedLength(int nDecodedLen) Get the maximum encoded length based on the provided decoded length.
-
Method Details
-
getMaximumEncodedLength
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- Parameters:
nDecodedLen- The decoded length. Always ≥ 0.- Returns:
- The maximum encoded length. Always ≥ 0.
-
encode
Encode a byte array to anOutputStream.- Parameters:
aDecodedBuffer- The byte array to be encoded. May benull.aOS- The output stream to write to. May not benulland is NOT closed afterwards!- Throws:
EncodeException- In case something goes wrong- Since:
- 9.0.0
-
encode
void encode(@Nullable byte[] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull @WillNotClose OutputStream aOS) Encode (part of) a byte array to anOutputStream.- 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!- Throws:
EncodeException- In case something goes wrong
-
getEncoded
Encode a byte array.- Specified by:
getEncodedin interfaceIByteArrayEncoder- Specified by:
getEncodedin interfaceIEncoder<byte[],byte[]> - Parameters:
aDecodedBuffer- The byte array to be encoded. May benull.- Returns:
- The encoded byte array or
nullif the parameter wasnull. - Throws:
EncodeException- In case something goes wrong
-
getEncoded
@Nullable @ReturnsMutableCopy default byte[] getEncoded(@Nullable byte[] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen) Encode a byte array.- Specified by:
getEncodedin interfaceIByteArrayEncoder- 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. - Throws:
EncodeException- In case something goes wrong
-
getEncoded
@Nullable @ReturnsMutableCopy default byte[] getEncoded(@Nullable String sDecoded, @Nonnull Charset aCharset) Encode the passed string.- Specified by:
getEncodedin interfaceIByteArrayEncoder- Parameters:
sDecoded- The string to be encoded. May benull.aCharset- The charset to be used. May not benull.- Returns:
nullif the input string isnull.- Throws:
EncodeException- In case something goes wrong
-
getEncodedAsString
-
getEncodedAsString
@Nullable default String getEncodedAsString(@Nullable byte[] aDecodedBuf, @Nonnegative int nOfs, @Nonnegative int nLen, @Nonnull Charset aCharset) -
getEncodedAsString
Encode the passed string and return the result as a String.- Parameters:
sDecoded- The string to be encoded. May benull.aCharset- The charset to be used. May not benull.- Returns:
nullif the input string isnull.- Throws:
EncodeException- In case something goes wrong
-