本文整理汇总了Java中org.apache.james.mime4j.codec.QuotedPrintableInputStream类的典型用法代码示例。如果您正苦于以下问题:Java QuotedPrintableInputStream类的具体用法?Java QuotedPrintableInputStream怎么用?Java QuotedPrintableInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuotedPrintableInputStream类属于org.apache.james.mime4j.codec包,在下文中一共展示了QuotedPrintableInputStream类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDecodingInputStream
import org.apache.james.mime4j.codec.QuotedPrintableInputStream; //导入依赖的package包/类
InputStream getDecodingInputStream(final InputStream rawInputStream, @Nullable String encoding) {
if (MimeUtil.ENC_BASE64.equals(encoding)) {
return new Base64InputStream(rawInputStream) {
@Override
public void close() throws IOException {
super.close();
rawInputStream.close();
}
};
}
if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) {
return new QuotedPrintableInputStream(rawInputStream) {
@Override
public void close() throws IOException {
super.close();
rawInputStream.close();
}
};
}
return rawInputStream;
}
示例2: decodeQ
import org.apache.james.mime4j.codec.QuotedPrintableInputStream; //导入依赖的package包/类
/**
* Decodes an encoded word encoded with the 'Q' encoding (described in
* RFC 2047) found in a header field body.
*
* @param encodedWord the encoded word to decode.
* @param charset the Java charset to use.
* @return the decoded string.
*/
private static String decodeQ(String encodedWord, String charset) {
/*
* Replace _ with =20
*/
StringBuilder sb = new StringBuilder();
for (int i = 0; i < encodedWord.length(); i++) {
char c = encodedWord.charAt(i);
if (c == '_') {
sb.append("=20");
} else {
sb.append(c);
}
}
byte[] bytes = sb.toString().getBytes(Charset.forName("US-ASCII"));
QuotedPrintableInputStream is = new QuotedPrintableInputStream(new ByteArrayInputStream(bytes));
try {
return CharsetSupport.readToString(is, charset);
} catch (IOException e) {
return null;
}
}
示例3: decodeQuotedPrintable
import org.apache.james.mime4j.codec.QuotedPrintableInputStream; //导入依赖的package包/类
/**
* Decodes a string containing quoted-printable encoded data.
*
* @param s the string to decode.
* @return the decoded bytes.
*/
private static byte[] decodeQuotedPrintable(String s, DecodeMonitor monitor) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] bytes = s.getBytes("US-ASCII");
QuotedPrintableInputStream is = new QuotedPrintableInputStream(
new ByteArrayInputStream(bytes), monitor);
int b = 0;
while ((b = is.read()) != -1) {
baos.write(b);
}
} catch (IOException e) {
// This should never happen!
throw new IllegalStateException(e);
}
return baos.toByteArray();
}