ByteArrayOutputStream has a protected "buf" member which is the buffer itself. I've never done this, but that member wouldn't be protected if you weren't intended to use it by subclassing. So what I'd try would be to write VincentsByteArrayOutputStream (a subclass of ByteArrayOutputStream) and give it a setByteBuffer() method, or have it take a byte[] as a constructor argument. I'd assume (of course,
you should thoroughly
test this assumption!) that if you set the initial buffer to be large enough, then it will never be reallocated, and all the written data will end up in the buffer you supply.
[ January 28, 2004: Message edited by: Ernest Friedman-Hill ]