code: private String readLine(InputStream in) throws IOException {
  	StringBuffer buf = new StringBuffer();
  	int c, length = 0;
  
  	while(true) {
  	    c = in.read();
  	    if (c == -1 || c == '\n' || length > 512) {
  		break;
  	    } else if (c == '\r') {
  		in.read();
  		return buf.toString();
  	    } else {
  		buf.append((char)c);
  		length++;
  	    }
  
  	}
  	return buf.toString();
      }
docs: Read a line of text from the given Stream and return it
  as a String.  Assumes lines end in CRLF.