code: public String readLine() throws IOException {
          StringBuilder str = new StringBuilder();
          while (true) {
              int c = read();
              if (c < 0) {
                  break;
              }
              if (c == '\n') {
                  // if possible consume another '\r'
                  int peek = stream.read();
                  if (peek != '\r' && peek >= 0){
                      stream.unread(peek);
                  }
                  break;
              }
              if (c == '\r') {
                  // if possible consume another '\n'
                  int peek = stream.read();
                  if (peek != '\n' && peek >= 0){
                      stream.unread(peek);
                  }
                  break;
              }
              str.append((char) c);
          }
          return str.toString();
      }
docs: Reads the next line.
  @return The next line or {@code null} if the end of the stream is
  reached.
  @throws IOException if reading fails.