// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package org.apache.commons.codec.net; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; import java.util.BitSet; import org.apache.commons.codec.BinaryDecoder; import org.apache.commons.codec.BinaryEncoder; import org.apache.commons.codec.Charsets; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.EncoderException; import org.apache.commons.codec.StringDecoder; import org.apache.commons.codec.StringEncoder; import org.apache.commons.codec.binary.StringUtils; // Referenced classes of package org.apache.commons.codec.net: // Utils public class QuotedPrintableCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, StringDecoder { private static final byte CR = 13; private static final byte ESCAPE_CHAR = 61; private static final byte LF = 10; private static final BitSet PRINTABLE_CHARS; private static final int SAFE_LENGTH = 73; private static final byte SPACE = 32; private static final byte TAB = 9; private final Charset charset; private final boolean strict; public QuotedPrintableCodec() { this(Charsets.UTF_8, false); } public QuotedPrintableCodec(String s) throws IllegalCharsetNameException, IllegalArgumentException, UnsupportedCharsetException { this(Charset.forName(s), false); } public QuotedPrintableCodec(Charset charset1) { this(charset1, false); } public QuotedPrintableCodec(Charset charset1, boolean flag) { charset = charset1; strict = flag; } public QuotedPrintableCodec(boolean flag) { this(Charsets.UTF_8, flag); } public static final byte[] decodeQuotedPrintable(byte abyte0[]) throws DecoderException { ByteArrayOutputStream bytearrayoutputstream; int i; if (abyte0 == null) { return null; } bytearrayoutputstream = new ByteArrayOutputStream(); i = 0; _L2: int j; byte byte0; if (i >= abyte0.length) { break MISSING_BLOCK_LABEL_119; } byte0 = abyte0[i]; if (byte0 != 61) { break MISSING_BLOCK_LABEL_90; } j = i + 1; if (abyte0[j] == 13) { break MISSING_BLOCK_LABEL_124; } try { i = Utils.digit16(abyte0[j]); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { throw new DecoderException("Invalid quoted-printable encoding", abyte0); } j++; bytearrayoutputstream.write((char)((i << 4) + Utils.digit16(abyte0[j]))); break MISSING_BLOCK_LABEL_124; j = i; if (byte0 != 13) { j = i; if (byte0 != 10) { bytearrayoutputstream.write(byte0); j = i; } } break MISSING_BLOCK_LABEL_124; return bytearrayoutputstream.toByteArray(); i = j + 1; if (true) goto _L2; else goto _L1 _L1: } private static int encodeByte(int i, boolean flag, ByteArrayOutputStream bytearrayoutputstream) { if (flag) { return encodeQuotedPrintable(i, bytearrayoutputstream); } else { bytearrayoutputstream.write(i); return 1; } } private static final int encodeQuotedPrintable(int i, ByteArrayOutputStream bytearrayoutputstream) { bytearrayoutputstream.write(61); char c = Character.toUpperCase(Character.forDigit(i >> 4 & 0xf, 16)); i = Character.toUpperCase(Character.forDigit(i & 0xf, 16)); bytearrayoutputstream.write(c); bytearrayoutputstream.write(i); return 3; } public static final byte[] encodeQuotedPrintable(BitSet bitset, byte abyte0[]) { return encodeQuotedPrintable(bitset, abyte0, false); } public static final byte[] encodeQuotedPrintable(BitSet bitset, byte abyte0[], boolean flag) { if (abyte0 == null) { return null; } BitSet bitset1 = bitset; if (bitset == null) { bitset1 = PRINTABLE_CHARS; } bitset = new ByteArrayOutputStream(); if (flag) { int i = 1; int k = 0; while (k < abyte0.length - 3) { int j1 = getUnsignedOctet(k, abyte0); if (i < 73) { if (!bitset1.get(j1)) { flag = true; } else { flag = false; } i += encodeByte(j1, flag, bitset); } else { if (!bitset1.get(j1) || isWhitespace(j1)) { flag = true; } else { flag = false; } encodeByte(j1, flag, bitset); bitset.write(61); bitset.write(13); bitset.write(10); i = 1; } k++; } k = getUnsignedOctet(abyte0.length - 3, abyte0); if (!bitset1.get(k) || isWhitespace(k) && i > 68) { flag = true; } else { flag = false; } if (i + encodeByte(k, flag, bitset) > 71) { bitset.write(61); bitset.write(13); bitset.write(10); } i = abyte0.length - 2; while (i < abyte0.length) { int l = getUnsignedOctet(i, abyte0); if (!bitset1.get(l) || i > abyte0.length - 2 && isWhitespace(l)) { flag = true; } else { flag = false; } encodeByte(l, flag, bitset); i++; } } else { int k1 = abyte0.length; int j = 0; while (j < k1) { byte byte0 = abyte0[j]; int i1 = byte0; if (byte0 < 0) { i1 = byte0 + 256; } if (bitset1.get(i1)) { bitset.write(i1); } else { encodeQuotedPrintable(i1, ((ByteArrayOutputStream) (bitset))); } j++; } } return bitset.toByteArray(); } private static int getUnsignedOctet(int i, byte abyte0[]) { byte byte0 = abyte0[i]; i = byte0; if (byte0 < 0) { i = byte0 + 256; } return i; } private static boolean isWhitespace(int i) { return i == 32 || i == 9; } public Object decode(Object obj) throws DecoderException { if (obj == null) { return null; } if (obj instanceof byte[]) { return decode((byte[])(byte[])obj); } if (obj instanceof String) { return decode((String)obj); } else { throw new DecoderException((new StringBuilder()).append("Objects of type ").append(obj.getClass().getName()).append(" cannot be quoted-printable decoded").toString()); } } public String decode(String s) throws DecoderException { return decode(s, getCharset()); } public String decode(String s, String s1) throws DecoderException, UnsupportedEncodingException { if (s == null) { return null; } else { return new String(decode(StringUtils.getBytesUsAscii(s)), s1); } } public String decode(String s, Charset charset1) throws DecoderException { if (s == null) { return null; } else { return new String(decode(StringUtils.getBytesUsAscii(s)), charset1); } } public byte[] decode(byte abyte0[]) throws DecoderException { return decodeQuotedPrintable(abyte0); } public Object encode(Object obj) throws EncoderException { if (obj == null) { return null; } if (obj instanceof byte[]) { return encode((byte[])(byte[])obj); } if (obj instanceof String) { return encode((String)obj); } else { throw new EncoderException((new StringBuilder()).append("Objects of type ").append(obj.getClass().getName()).append(" cannot be quoted-printable encoded").toString()); } } public String encode(String s) throws EncoderException { return encode(s, getCharset()); } public String encode(String s, String s1) throws UnsupportedEncodingException { if (s == null) { return null; } else { return StringUtils.newStringUsAscii(encode(s.getBytes(s1))); } } public String encode(String s, Charset charset1) { if (s == null) { return null; } else { return StringUtils.newStringUsAscii(encode(s.getBytes(charset1))); } } public byte[] encode(byte abyte0[]) { return encodeQuotedPrintable(PRINTABLE_CHARS, abyte0, strict); } public Charset getCharset() { return charset; } public String getDefaultCharset() { return charset.name(); } static { PRINTABLE_CHARS = new BitSet(256); for (int i = 33; i <= 60; i++) { PRINTABLE_CHARS.set(i); } for (int j = 62; j <= 126; j++) { PRINTABLE_CHARS.set(j); } PRINTABLE_CHARS.set(9); PRINTABLE_CHARS.set(32); } }