public static InputStream decode(InputStream in, String encoding) throws IOException { if (encoding == null) { return in; } encoding = encoding.toLowerCase(); // some encodings are just pass-throughs, with no real decoding. if ("binary".equals(encoding) || "7bit".equals(encoding) || "8bit".equals(encoding)) { return in; } else if ("base64".equals(encoding)) { return new Base64DecoderStream(in); } else if ("quoted-printable".equals(encoding)) { return new QuotedPrintableDecoderStream(in); } else { throw new IOException("Unknown encoding " + encoding); } } public static boolean isTypeSupported(String contentType, List<String> types) {
return decodeNonspaceChar(ch); cachedCharacter = decodeNonspaceChar(ch);
private int decodeNonspaceChar(int ch) throws IOException { if (ch != '=') { return ch; } // we need to get two characters after the quotation marker byte[] b = new byte[2]; if (in.read(b) < 2) { throw new IOException("Truncated quoted printable data"); } if (b[0] == '\r') { // we've found an encoded carriage return. The next char needs to be a newline if (b[1] != '\n') { throw new IOException("Invalid quoted printable encoding"); } // this was a soft linebreak inserted by the encoding. We just toss this away // on decode. We need to return something, so recurse and decode the next. return read(); } // this is a hex pair we need to convert back to a single byte. b[0] = DECODING_TABLE[b[0]]; b[1] = DECODING_TABLE[b[1]]; return (b[0] << 4) | b[1]; }
private int decodeNonspaceChar(int ch) throws IOException { if (ch != '=') { return ch; } // we need to get two characters after the quotation marker byte[] b = new byte[2]; if (in.read(b) < 2) { throw new IOException("Truncated quoted printable data"); } if (b[0] == '\r') { // we've found an encoded carriage return. The next char needs to be a newline if (b[1] != '\n') { throw new IOException("Invalid quoted printable encoding"); } // this was a soft linebreak inserted by the encoding. We just toss this away // on decode. We need to return something, so recurse and decode the next. return read(); } // this is a hex pair we need to convert back to a single byte. b[0] = DECODING_TABLE[b[0]]; b[1] = DECODING_TABLE[b[1]]; return (b[0] << 4) | b[1]; }
public static InputStream decode(InputStream in, String encoding) throws IOException { if (encoding == null) { return in; } encoding = encoding.toLowerCase(); // some encodings are just pass-throughs, with no real decoding. if ("binary".equals(encoding) || "7bit".equals(encoding) || "8bit".equals(encoding)) { return in; } else if ("base64".equals(encoding)) { return new Base64DecoderStream(in); } else if ("quoted-printable".equals(encoding)) { return new QuotedPrintableDecoderStream(in); } else { throw new IOException("Unknown encoding " + encoding); } } public static boolean isTypeSupported(String contentType, List<String> types) {
return decodeNonspaceChar(ch); cachedCharacter = decodeNonspaceChar(ch);
private int decodeNonspaceChar(int ch) throws IOException { if (ch != '=') { return ch; } // we need to get two characters after the quotation marker byte[] b = new byte[2]; if (in.read(b) < 2) { throw new IOException("Truncated quoted printable data"); } if (b[0] == '\r') { // we've found an encoded carriage return. The next char needs to be a newline if (b[1] != '\n') { throw new IOException("Invalid quoted printable encoding"); } // this was a soft linebreak inserted by the encoding. We just toss this away // on decode. We need to return something, so recurse and decode the next. return read(); } // this is a hex pair we need to convert back to a single byte. b[0] = DECODING_TABLE[b[0]]; b[1] = DECODING_TABLE[b[1]]; return (b[0] << 4) | b[1]; }
new QuotedPrintableDecoderStream(stream)); if (!StringUtils.isEmpty(fileName)) { ((AttachmentDataSource)source).setName(fileName);
return decodeNonspaceChar(ch); cachedCharacter = decodeNonspaceChar(ch);
private int decodeNonspaceChar(int ch) throws IOException { if (ch != '=') { return ch; } // we need to get two characters after the quotation marker byte[] b = new byte[2]; if (in.read(b) < 2) { throw new IOException("Truncated quoted printable data"); } if (b[0] == '\r') { // we've found an encoded carriage return. The next char needs to be a newline if (b[1] != '\n') { throw new IOException("Invalid quoted printable encoding"); } // this was a soft linebreak inserted by the encoding. We just toss this away // on decode. We need to return something, so recurse and decode the next. return read(); } // this is a hex pair we need to convert back to a single byte. b[0] = DECODING_TABLE[b[0]]; b[1] = DECODING_TABLE[b[1]]; return (b[0] << 4) | b[1]; }
new QuotedPrintableDecoderStream(stream)); if (!StringUtils.isEmpty(fileName)) { ((AttachmentDataSource)source).setName(fileName);
return decodeNonspaceChar(ch); cachedCharacter = decodeNonspaceChar(ch);