1 36 package org.columba.ristretto.coder; 37 38 import java.io.FilterInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 42 43 50 public class QuotedPrintableDecoderInputStream extends FilterInputStream { 51 52 57 public QuotedPrintableDecoderInputStream(InputStream arg0) { 58 super(arg0); 59 } 60 61 68 private int readNextOctet() throws IOException { 69 int read = in.read(); 70 if( read == -1) return -1; 71 72 if( read == '=') { 73 int first = in.read(); 74 switch( first ) { 75 case('\r') : { 76 in.read(); return readNextOctet(); 78 } 79 80 case('\n') : { 81 return readNextOctet(); 82 } 83 84 default : { 85 int second = in.read(); 86 char[] number = { (char) first, (char) second }; 87 try { 88 return Integer.parseInt( new String (number), 16); 89 } catch (NumberFormatException e) { 90 return '?'; 92 } 93 } 94 } 95 96 } else { 97 return read; 98 } 99 } 100 101 102 105 public int read() throws IOException { 106 return readNextOctet(); 107 } 108 109 112 public int read(byte[] arg0, int arg1, int arg2) throws IOException { 113 int next; 114 for( int i=0; i<arg2; i++) { 115 next = read(); 116 if( next == -1 ) { 117 if( i == 0 ) { 118 return -1; 119 } else { 120 return i; 121 } 122 } 123 arg0[arg1+i] = (byte) next; 124 } 125 return arg2; 126 } 127 128 } 129 | Popular Tags |