1 36 package org.columba.ristretto.smtp; 37 38 import java.io.FilterInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 42 import org.columba.ristretto.io.ConnectionDroppedException; 43 import org.columba.ristretto.parser.ParserException; 44 import org.columba.ristretto.smtp.parser.SMTPResponseParser; 45 46 53 public class SMTPInputStream extends FilterInputStream { 54 55 private StringBuffer lineBuffer; 56 57 63 public SMTPInputStream(InputStream arg0) { 64 super(arg0); 65 66 lineBuffer = new StringBuffer (); 67 } 68 69 78 public SMTPResponse readSingleLineResponse() 79 throws IOException , SMTPException { 80 readLineInBuffer(); 81 82 try { 83 return SMTPResponseParser.parse(lineBuffer); 84 } catch (ParserException e) { 85 throw new SMTPException("Malformed answer from server", e); 86 } 87 } 88 89 90 95 private void readLineInBuffer() throws IOException { 96 lineBuffer.delete(0, lineBuffer.length()); 98 99 int read = in.read(); 100 while (read != '\r' && read != -1) { 102 lineBuffer.append((char) read); 103 read = in.read(); 104 } 105 lineBuffer.append((char) read); 106 107 read = in.read(); 109 if( read != '\n' ) throw new ConnectionDroppedException(); 110 lineBuffer.append((char) read); 111 } 112 113 } 114 | Popular Tags |