code: private String readLine() throws IOException {
      StringBuffer sbuf = new StringBuffer();
      int result;
      String line;
  
      do {
        result = in.readLine(buf, 0, buf.length);  // does +=
        if (result != -1) {
          sbuf.append(new String(buf, 0, result, encoding));
        }
      } while (result == buf.length);  // loop only if the buffer was filled
  
      if (sbuf.length() == 0) {
        return null;  // nothing read, must be at the end of stream
      }
  
      // Cut off the trailing \n or \r\n
      // It should always be \r\n but IE5 sometimes does just \n
      // Thanks to Luke Blaikie for helping make this work with \n
      int len = sbuf.length();
      if (len >= 2 && sbuf.charAt(len - 2) == '\r') {
        sbuf.setLength(len - 2);  // cut \r\n
      }
      else if (len >= 1 && sbuf.charAt(len - 1) == '\n') {
        sbuf.setLength(len - 1);  // cut \n
      }
      return sbuf.toString();
    }
docs: Read the next line of input.
  
  @return     a String containing the next line of input from the stream,
  or null to indicate the end of the stream.
  @exception IOException	if an input or output exception has occurred.