@Test
    public void requireThatChunkedReadWorks() throws IOException {
        ByteLimitedInputStream stream = create("abcdefghijklmnopqr".getBytes(StandardCharsets.US_ASCII), 9);

        assertEquals(9, stream.available());
        byte[] toBuf = new byte[4];
        assertEquals(4, stream.read(toBuf));
        assertEquals(97, toBuf[0]);
        assertEquals(98, toBuf[1]);
        assertEquals(99, toBuf[2]);
        assertEquals(100, toBuf[3]);
        assertEquals(5, stream.available());

        assertEquals(4, stream.read(toBuf));
        assertEquals(101, toBuf[0]);
        assertEquals(102, toBuf[1]);
        assertEquals(103, toBuf[2]);
        assertEquals(104, toBuf[3]);
        assertEquals(1, stream.available());

        assertEquals(1, stream.read(toBuf));
        assertEquals(105, toBuf[0]);
        assertEquals(0, stream.available());

        assertEquals(-1, stream.read(toBuf));
        assertEquals(0, stream.available());
    }
@author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
@since 5.1.23
vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/util/ByteLimitedInputStreamTestCase.java