### Question:
DataChunkInputStream extends InputStream { @Override public int read() throws IOException { if (oneByte == null) { oneByte = new byte[1]; } int r = read(oneByte, 0, 1); if (r < 0) { return r; } return oneByte[0] & 0xFF; } DataChunkInputStream(Flow.Publisher<DataChunk> originalPublisher);  DataChunkInputStream(Flow.Publisher<DataChunk> originalPublisher, boolean validate); @Override void close(); @Override int read(); @Override int read(byte[] buf, int off, int len);  }### Answer:
@Test public void emptyTrailingChunk() throws IOException { InputStream is = new DataChunkInputStream(Multi.just(DataChunk.create("test".getBytes()), DataChunk.create(new byte[0]))); int c; StringBuilder sb = new StringBuilder(); while ((c = is.read()) != -1) { sb.append((char) c); } assertThat(sb.toString(), is("test")); }
@Test public void emptyChunk() throws IOException { InputStream is = new DataChunkInputStream(Multi.just(DataChunk.create("foo".getBytes()), DataChunk.create(new byte[0]), DataChunk.create("bar".getBytes()))); int c; StringBuilder sb = new StringBuilder(); while ((c = is.read()) != -1) { sb.append((char) c); } assertThat(sb.toString(), is("foobar")); }
@Test public void chunksWithManyBuffers() throws IOException { InputStream is = new DataChunkInputStream(Multi.just( DataChunk.create(ByteBuffer.wrap("foo".getBytes()), ByteBuffer.wrap(",xxx".getBytes()).position(4)), DataChunk.create(ByteBuffer.wrap(",bar".getBytes()), ByteBuffer.wrap(",bob".getBytes())))); int c; StringBuilder sb = new StringBuilder(); while ((c = is.read()) != -1) { sb.append((char) c); } assertThat(sb.toString(), is("foo,bar,bob")); }
@Test public void chunkWith0xFFValue() { final byte[] bytes = new byte[]{ 0, 1, 2, 3, 4, 5, 6, (byte) 0xFF, 7, 8, 9, 10 }; InputStream is = new DataChunkInputStream( new DataChunkPublisher( new DataChunk[]{DataChunk.create(bytes)})); try { byte[] readBytes = new byte[bytes.length]; is.read(readBytes); if (!Arrays.equals(bytes, readBytes)) { fail("expected: " + Arrays.toString(bytes) + ", actual: " + Arrays.toString(readBytes)); } } catch (IOException ex) { fail(ex); } }