code: private static int forAllLines(InputStream is, byte separator, LineConsumer lineConsumer) throws IOException {
      int lines = 0;
      byte[] buffer = new byte[0];
      int b, pos = 0;
      while ((b = is.read()) != -1) {
        if (b == separator) {
          buffer = lineConsumer.process(buffer, pos);
          pos = 0;
          lines++;
        } else {
          if (pos >= buffer.length) {
            buffer = java.util.Arrays.copyOf(buffer, buffer.length + Math.max(10, buffer.length / 10));
          }
          buffer[pos++] = (byte) b;
        }
      }
  
      if (pos > 0) {
        lineConsumer.process(buffer, pos);
        lines++;
      }
      return lines;
    }
docs: Read all byte-separated sequences.