class ChunkedOutputStream extends FilterOutputStream {

    @Override
    public void write(byte[] data, int srcOffset, int length) throws IOException {
        int bytes = length;
        int dstOffset = srcOffset;
        while(bytes > 0) {
            int chunk = Math.min(bytes, chunkSize);
            out.write(data, dstOffset, chunk);
            bytes -= chunk;
            dstOffset += chunk;
        }
    }

    public  ChunkedOutputStream(final OutputStream stream, int chunkSize);
    public  ChunkedOutputStream(final OutputStream stream);

}