1 18 19 package org.apache.tools.mail; 20 21 import java.io.InputStream ; 22 import java.io.IOException ; 23 import java.io.BufferedReader ; 24 import java.io.InputStreamReader ; 25 26 34 public class SmtpResponseReader { 35 protected BufferedReader reader = null; 37 private StringBuffer result = new StringBuffer (); 39 40 44 public SmtpResponseReader(InputStream in) { 45 reader = new BufferedReader (new InputStreamReader (in)); 46 } 47 48 56 public String getResponse() throws IOException { 57 result.setLength(0); 58 String line = reader.readLine(); 59 if (line != null && line.length() >= 3) { 60 result.append(line.substring(0, 3)); 61 result.append(" "); 62 } 63 64 while (line != null) { 65 append(line); 66 if (!hasMoreLines(line)) { 67 break; 68 } 69 line = reader.readLine(); 70 } 71 return result.toString().trim(); 72 } 73 74 78 public void close() throws IOException { 79 reader.close(); 80 } 81 82 87 protected boolean hasMoreLines(String line) { 88 return line.length() > 3 && line.charAt(3) == '-'; 89 } 90 91 94 private void append(String line) { 95 if (line.length() > 4) { 96 result.append(line.substring(4)); 97 result.append(" "); 98 } 99 } 100 } 101 | Popular Tags |