FileDocCategorySizeDatePackage
SmtpResponseReader.javaAPI DocApache Ant 1.703075Wed Dec 13 06:16:20 GMT 2006org.apache.tools.mail

SmtpResponseReader

public class SmtpResponseReader extends Object
A wrapper around the raw input from the SMTP server that assembles multi line responses into a single String.

The same rules used here would apply to FTP and other Telnet based protocols as well.

Fields Summary
protected BufferedReader
reader
private StringBuffer
result
Constructors Summary
public SmtpResponseReader(InputStream in)
Wrap this input stream.

param
in the stream to wrap.


                   
       
        reader = new BufferedReader(new InputStreamReader(in));
    
Methods Summary
private voidappend(java.lang.String line)
Append the text from this line of the resonse.

        if (line.length() > 4) {
            result.append(line.substring(4));
            result.append(" ");
        }
    
public voidclose()
Closes the underlying stream.

throws
IOException on error.

        reader.close();
    
public java.lang.StringgetResponse()
Read until the server indicates that the response is complete.

return
Responsecode (3 digits) + Blank + Text from all response line concatenated (with blanks replacing the \r\n sequences).
throws
IOException on error.

        result.setLength(0);
        String line = reader.readLine();
        if (line != null && line.length() >= 3) {
            result.append(line.substring(0, 3));
            result.append(" ");
        }

        while (line != null) {
            append(line);
            if (!hasMoreLines(line)) {
                break;
            }
            line = reader.readLine();
        }
        return result.toString().trim();
    
protected booleanhasMoreLines(java.lang.String line)
Should we expect more input?

param
line the line to check.
return
true if there are more lines to check.

        return line.length() > 3 && line.charAt(3) == '-";