/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * * @param printable * bitset of characters deemed quoted-printable * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public static final byte[] encodeQuotedPrintable(final BitSet printable, final byte[] bytes) { return encodeQuotedPrintable(printable, bytes, false); }
@Override protected byte[] doEncoding(final byte[] bytes) { if (bytes == null) { return null; } final byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * <p> * Depending on the selection of the {@code strict} parameter, this function either implements the full ruleset * or only a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ @Override public byte[] encode(final byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes, strict); }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * </p> * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public byte[] encode(byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes); }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
/** * Write a byte to the buffer. * * @param b * byte to write * @param encode * indicates whether the octet shall be encoded * @param buffer * the buffer to write to * @return the number of bytes that have been written to the buffer */ private static int encodeByte(final int b, final boolean encode, final ByteArrayOutputStream buffer) { if (encode) { return encodeQuotedPrintable(b, buffer); } buffer.write(b); return 1; }
buffer.write(b); } else { encodeQuotedPrintable(b, buffer);
buffer.write(b); } else { encodeQuotedPrintable(b, buffer);
@Test public void testEncodeUrlWithNullBitSet() throws Exception { final QuotedPrintableCodec qpcodec = new QuotedPrintableCodec(); final String plain = "1+1 = 2"; final String encoded = new String(QuotedPrintableCodec. encodeQuotedPrintable(null, plain.getBytes(Charsets.UTF_8))); assertEquals("Basic quoted-printable encoding test", "1+1 =3D 2", encoded); assertEquals("Basic quoted-printable decoding test", plain, qpcodec.decode(encoded)); }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ @Override public byte[] encode(final byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes); }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * </p> * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public byte[] encode(byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes); }
@Override protected byte[] doEncoding(final byte[] bytes) { if (bytes == null) { return null; } final byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
protected byte[] doEncoding(byte[] bytes) throws EncoderException { if (bytes == null) { return null; } byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes); if (this.encodeBlanks) { for (int i = 0; i < data.length; i++) { if (data[i] == BLANK) { data[i] = UNDERSCORE; } } } return data; }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * </p> * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public byte[] encode(byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes); }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * * @param printable * bitset of characters deemed quoted-printable * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public static final byte[] encodeQuotedPrintable(BitSet printable, final byte[] bytes) { return encodeQuotedPrintable(printable, bytes, false); }
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * <p> * Depending on the selection of the {@code strict} parameter, this function either implements the full ruleset * or only a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ @Override public byte[] encode(final byte[] bytes) { return encodeQuotedPrintable(PRINTABLE_CHARS, bytes, strict); }