1 21 22 27 28 package com.sun.mail.util; 29 30 import java.io.*; 31 32 40 41 public class QPDecoderStream extends FilterInputStream { 42 protected byte[] ba = new byte[2]; 43 protected int spaces = 0; 44 45 50 public QPDecoderStream(InputStream in) { 51 super(new PushbackInputStream(in, 2)); } 53 54 66 public int read() throws IOException { 67 if (spaces > 0) { 68 spaces--; 70 return ' '; 71 } 72 73 int c = in.read(); 74 75 if (c == ' ') { 76 while ((c = in.read()) == ' ') 78 spaces++; 79 80 if (c == '\r' || c == '\n' || c == -1) 81 spaces = 0; 84 else { 85 ((PushbackInputStream)in).unread(c); 87 c = ' '; 88 } 89 return c; } 91 else if (c == '=') { 92 int a = in.read(); 94 95 if (a == '\n') { 96 101 return read(); 102 } else if (a == '\r') { 103 int b = in.read(); 105 if (b != '\n') 106 109 ((PushbackInputStream)in).unread(b); 110 return read(); 111 } else if (a == -1) { 112 return -1; 114 } else { 115 ba[0] = (byte)a; 116 ba[1] = (byte)in.read(); 117 try { 118 return ASCIIUtility.parseInt(ba, 0, 2, 16); 119 } catch (NumberFormatException nex) { 120 126 127 ((PushbackInputStream)in).unread(ba); 128 return c; 129 } 130 } 131 } 132 return c; 133 } 134 135 149 public int read(byte[] buf, int off, int len) throws IOException { 150 int i, c; 151 for (i = 0; i < len; i++) { 152 if ((c = read()) == -1) { 153 if (i == 0) i = -1; break; 156 } 157 buf[off+i] = (byte)c; 158 } 159 return i; 160 } 161 162 166 public boolean markSupported() { 167 return false; 168 } 169 170 177 public int available() throws IOException { 178 return in.available(); 181 } 182 183 194 } 195 | Popular Tags |