you can add writeTo(byte[] buffer, int start, int length) in CapacityByteArrayOutputStream
That should make things easier