I would like to convert an iterator of Strings to Inputstream of bytes. Usually, I can do this by appending all the strings in a `StringBuilder` and doing:
`InputStream is = new ByteArrayInputStream(sb.toString().getBytes());`

But I want to do it lazily because my iterable is provided by Spark and could be very large in length. I found this example to do it in Scala:

```
  def rowsToInputStream(rows: Iterator[String], delimiter: String): InputStream = {
  val bytes: Iterator[Byte] = rows.map { row =>
    (row + "\n").getBytes
  }.flatten

  new InputStream {
    override def read(): Int = if (bytes.hasNext) {
      bytes.next & 0xff // bitwise AND - make the signed byte an unsigned int from 0-255
    } else {
      -1
    }
  }
}

```

But I could not find an easy way to convert this into Java. I converted the `iterator` to stream using `Spliterators.spliteratorUnknownSize` but then `getBytes` outputs an array which could not flatten easily. Overall it became pretty messy.

Is there an elegant way to do this in Java?