code: private static String readLine(InputStream is) throws IOException {
          StringBuilder builder = new StringBuilder();
          while (true) {
              int ch = is.read();
              if (ch == '\r') {
                  ch = is.read();
                  if (ch == '\n') {
                      break;
                  } else {
                      throw new IOException("unexpected char after \\r: " + ch);
                  }
              } else if (ch == -1) {
                  if (builder.length() > 0) {
                      throw new IOException("unexpected end of stream");
                  }
                  break;
              }
              builder.append((char) ch);
          }
          return builder.toString();
      }
docs: Read a \r\n terminated line from an InputStream.
  
  @return line without the newline or empty String if InputStream is empty