I want an InputStream to a sequence of bytes: 0, 1, 2, ... 255.
I can of course create a new byte[0x100], create a loop of int, fill it with the int values cast to byte (don't get me started on Java's signed byte type), and then form a ByteArrayInputStream from that.
But surely with Java 8 there is a better, more compact, and cleverer way. The trick seems to be generating the array of bytes. I found elsewhere that with int it's as easy as the following:
final int[] values = IntStream.range(0, 0x100).toArray();
But I need a byte array, and there is no ByteStream. Perhaps there is an IntStream collection function that could collect the int values into a byte[] array? Or something even cleverer?
InputStreamthat produces a particular sequence is where I want to end, not start. Abyte[]seems an obvious means, but feel free to skip the byte array if you have a more direct trick for creating anInputStream.0–255for the sake of argument.