public final String readLine() throws IOException {
    StringBuffer input = new StringBuffer();
    int c = -1;
    boolean eol = false;

    while (!eol) {
      switch (c = read()) {
        case -1:
        case '\n':
          eol = true;
          break;
        case '\r':
          eol = true;
          long cur = getFilePointer();
          if ((read()) != '\n') {
            seek(cur);
          }
          break;
        default:
          input.append((char) c);
          break;
      }
    }

    if ((c == -1) && (input.length() == 0)) {
      return null;
    }
    return input.toString();
  }