1 21 22 27 28 package com.sun.mail.util; 29 30 import java.io.*; 31 32 38 39 public class QEncoderStream extends QPEncoderStream { 40 41 private String specials; 42 private static String WORD_SPECIALS = "=_?\"#$%&'(),.:;<>@[\\]^`{|}~"; 43 private static String TEXT_SPECIALS = "=_?"; 44 45 51 public QEncoderStream(OutputStream out, boolean encodingWord) { 52 super(out, Integer.MAX_VALUE); 57 specials = encodingWord ? WORD_SPECIALS : TEXT_SPECIALS; 60 } 61 62 67 public void write(int c) throws IOException { 68 c = c & 0xff; if (c == ' ') 70 output('_', false); 71 else if (c < 040 || c >= 0177 || specials.indexOf(c) >= 0) 72 output(c, true); 74 else output(c, false); 76 } 77 78 81 public static int encodedLength(byte[] b, boolean encodingWord) { 82 int len = 0; 83 String specials = encodingWord ? WORD_SPECIALS: TEXT_SPECIALS; 84 for (int i = 0; i < b.length; i++) { 85 int c = b[i] & 0xff; if (c < 040 || c >= 0177 || specials.indexOf(c) >= 0) 87 len += 3; else 90 len++; 91 } 92 return len; 93 } 94 95 106 } 107 | Popular Tags |