Class QuotedPrintableCodec

java.lang.Object
com.helger.base.codec.impl.QuotedPrintableCodec
All Implemented Interfaces:
IByteArrayCodec, IByteArrayDecoder, IByteArrayEncoder, IByteArrayStreamDecoder, IByteArrayStreamEncoder, ICodec<byte[]>, IDecoder<byte[],byte[]>, IEncoder<byte[],byte[]>

@NotThreadSafe public class QuotedPrintableCodec extends Object implements IByteArrayCodec
Encoder and decoder for quoted printable stuff. Uses "=" as the escape char.
Author:
Philip Helger
  • Field Details

  • Constructor Details

    • QuotedPrintableCodec

      public QuotedPrintableCodec()
      Default constructor with the UTF-8 charset.
    • QuotedPrintableCodec

      public QuotedPrintableCodec(@NonNull BitSet aPrintableChars)
      Constructor using a custom set of printable characters.
      Parameters:
      aPrintableChars - The set of printable characters. May not be null.
  • Method Details

    • getDefaultPrintableChars

      @ReturnsMutableCopy public static @NonNull BitSet getDefaultPrintableChars()
      Returns:
      A copy of the default bit set to be used.
    • getPrintableChars

      @ReturnsMutableCopy public @NonNull BitSet getPrintableChars()
      Returns:
      A copy of the default bit set to be used. Never null.
    • writeEncodeQuotedPrintableByte

      public static final void writeEncodeQuotedPrintableByte(int b, @NonNull OutputStream aOS) throws IOException
      Encodes byte into its quoted-printable representation. It will always be 3 characters.
      Parameters:
      b - byte to encode
      aOS - the output stream to write to
      Throws:
      IOException - In case writing to the OutputStream failed
    • encode

      public void encode(byte @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS)
      Encode the passed decoded buffer using quoted-printable encoding and write it to the output stream.
      Specified by:
      encode in interface IByteArrayStreamEncoder
      Parameters:
      aDecodedBuffer - The buffer to be encoded. May be null.
      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 be null.
    • decode

      public void decode(byte @Nullable [] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull OutputStream aOS)
      Decode the passed quoted-printable encoded buffer and write the decoded bytes to the output stream.
      Specified by:
      decode in interface IByteArrayStreamDecoder
      Parameters:
      aEncodedBuffer - The quoted-printable encoded buffer to be decoded. May be null.
      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 be null.