Interface IByteArrayStreamEncoder

All Superinterfaces:
IByteArrayEncoder, IEncoder<byte[],byte[]>
All Known Subinterfaces:
IByteArrayCodec
All Known Implementing Classes:
Base16Codec, Base32Codec, Base64Codec, FlateCodec, GZIPCodec, IdentityByteArrayCodec, LZWCodec, QuotedPrintableCodec, RFC3986Codec
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface IByteArrayStreamEncoder extends IByteArrayEncoder
Interface for a single encoder of bytes, based on streams.
Author:
Philip Helger
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    encode(byte @Nullable [] aDecodedBuffer, int nOfs, int nLen, @NonNull OutputStream aOS)
    Encode (part of) a byte array to an OutputStream.
    default void
    encode(byte @Nullable [] aDecodedBuffer, @NonNull OutputStream aOS)
    Encode a byte array to an OutputStream.
    default byte @Nullable []
    getEncoded(byte @Nullable [] aDecodedBuffer)
    Encode a byte array.
    default byte @Nullable []
    getEncoded(byte @Nullable [] aDecodedBuffer, int nOfs, int nLen)
    Encode a byte array.
    default byte @Nullable []
    getEncoded(@Nullable String sDecoded, @NonNull Charset aCharset)
    Encode the passed string.
    default @Nullable String
    getEncodedAsString(byte @Nullable [] aDecodedBuf, int nOfs, int nLen, @NonNull Charset aCharset)
    Encode a portion of a byte array and return the result as a string.
    default @Nullable String
    getEncodedAsString(byte @Nullable [] aDecodedBuf, @NonNull Charset aCharset)
    Encode a byte array and return the result as a string.
    default @Nullable String
    getEncodedAsString(@Nullable String sDecoded, @NonNull Charset aCharset)
    Encode the passed string and return the result as a String.
    default int
    getMaximumEncodedLength(int nDecodedLen)
    Get the maximum encoded length based on the provided decoded length.
  • Method Details

    • getMaximumEncodedLength

      @Nonnegative default int getMaximumEncodedLength(@Nonnegative int nDecodedLen)
      Description copied from interface: IByteArrayEncoder
      Get 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:
      getMaximumEncodedLength in interface IByteArrayEncoder
      Parameters:
      nDecodedLen - The decoded length. Always ≥ 0.
      Returns:
      The maximum encoded length. Always ≥ 0.
    • encode

      default void encode(byte @Nullable [] aDecodedBuffer, @WillNotClose @NonNull OutputStream aOS)
      Encode a byte array to an OutputStream.
      Parameters:
      aDecodedBuffer - The byte array to be encoded. May be null.
      aOS - The output stream to write to. May not be null and is NOT closed afterwards!
      Throws:
      EncodeException - In case something goes wrong
      Since:
      9.0.0
    • encode

      void encode(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS)
      Encode (part of) a byte array to an OutputStream.
      Parameters:
      aDecodedBuffer - The byte array to be encoded. May be null.
      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 be null and is NOT closed afterwards!
      Throws:
      EncodeException - In case something goes wrong
    • getEncoded

      @ReturnsMutableCopy default byte @Nullable [] getEncoded(byte @Nullable [] aDecodedBuffer)
      Encode a byte array.
      Specified by:
      getEncoded in interface IByteArrayEncoder
      Specified by:
      getEncoded in interface IEncoder<byte[],byte[]>
      Parameters:
      aDecodedBuffer - The byte array to be encoded. May be null.
      Returns:
      The encoded byte array or null if the parameter was null.
      Throws:
      EncodeException - In case something goes wrong
    • getEncoded

      @ReturnsMutableCopy default byte @Nullable [] getEncoded(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen)
      Encode a byte array.
      Specified by:
      getEncoded in interface IByteArrayEncoder
      Parameters:
      aDecodedBuffer - The byte array to be encoded. May be null.
      nOfs - Offset into the byte array to start from.
      nLen - Number of bytes starting from offset to consider.
      Returns:
      The encoded byte array or null if the parameter was null.
      Throws:
      EncodeException - In case something goes wrong
    • getEncoded

      @ReturnsMutableCopy default byte @Nullable [] getEncoded(@Nullable String sDecoded, @NonNull Charset aCharset)
      Encode the passed string.
      Specified by:
      getEncoded in interface IByteArrayEncoder
      Parameters:
      sDecoded - The string to be encoded. May be null.
      aCharset - The charset to be used. May not be null.
      Returns:
      null if the input string is null.
      Throws:
      EncodeException - In case something goes wrong
    • getEncodedAsString

      default @Nullable String getEncodedAsString(byte @Nullable [] aDecodedBuf, @NonNull Charset aCharset)
      Encode a byte array and return the result as a string.
      Parameters:
      aDecodedBuf - The byte array to be encoded. May be null.
      aCharset - The charset to be used for the result string. May not be null.
      Returns:
      null if the input buffer is null.
      Throws:
      EncodeException - In case something goes wrong
    • getEncodedAsString

      default @Nullable String getEncodedAsString(byte @Nullable [] aDecodedBuf, @Nonnegative int nOfs, @Nonnegative int nLen, @NonNull Charset aCharset)
      Encode a portion of a byte array and return the result as a string.
      Parameters:
      aDecodedBuf - The byte array to be encoded. May be null.
      nOfs - Offset into the byte array to start from.
      nLen - Number of bytes starting from offset to consider.
      aCharset - The charset to be used for the result string. May not be null.
      Returns:
      null if the input buffer is null.
      Throws:
      EncodeException - In case something goes wrong
    • getEncodedAsString

      default @Nullable String getEncodedAsString(@Nullable String sDecoded, @NonNull Charset aCharset)
      Encode the passed string and return the result as a String.
      Parameters:
      sDecoded - The string to be encoded. May be null.
      aCharset - The charset to be used. May not be null.
      Returns:
      null if the input string is null.
      Throws:
      EncodeException - In case something goes wrong