code: protected String getNextLine(int newlineCount) throws IOException {
          if (newlineCount == 0) {
              return "";
          }
          StringBuffer str = new StringBuffer();
          int b;
          while (pis.available() > 0) {
              b = pis.read();
              if (b == -1) {
                  return "";
              }
              if (b == '\n') {
                  newlineCount--;
                  if (newlineCount == 0) {
                      log.debug("Read lines: " + str.toString());
                      String[] lines = str.toString().split("\n");
                      // FIXME: this leads to queuing lines so we will have time lag!
                      return lines[lines.length - 1];
                  }
              }
              str.append((char) b);
          }
          return "";
      }
docs: Method retrieves next line from received bytes sequence
  
  @param newlineCount
  @return next command line
  @throws IOException