ChunkingInputStream extends FilterInputStream { @Override public int read() throws IOException { fill(); if (buff.length() > 0) return buff.remove(); return -1; } ChunkingInputStream(InputStream in);  ChunkingInputStream(InputStream in, int size); @Override int read(); @Override int read(byte[] b, int off, int len);  }
@Test public void testRead() throws IOException { data = new byte[16385]; for (int i = 0; i < data.length; i++) data[i] = (byte) (i % 256); InputStream is = new ByteArrayInputStream(data); is = new ChunkingInputStream(is); is = new ChunkedInputStream(is); byte[] buff = new byte[data.length + 1024]; int read = 0, got; while ((got = is.read(buff, read, Math.min(1024, buff.length - read))) > -1) { logger.fine("Read " + got); read += got; } assertEquals(data.length, read); compare(data, 0, buff, 0, read); }