Subject | OT - Stream Question |
---|---|
Author | Robert DiFalco |
Post date | 2003-06-11T19:35:28Z |
Is there a way to have a ByteArrayInputStream and ByteArrayOutputStream
use the same buffer rather than reallocate. Basically, when using
Jaybird, I have a lot of code something like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
someObject.write( baos );
statement.setBinaryStream( COLUMN_BLOB, new ByteArrayInputStream(
baos.getBytes() ) );
I'm sure I'm doing something stupid here, but it seems silly to have to
reallocate the bytes from "baos" then copy then over to the buffer in
"bais". In the past, I've just reimplemented these to Stream classes to
be able to reference each other's buffers but there must be an easier
way to do it.
TIA,
Robert
use the same buffer rather than reallocate. Basically, when using
Jaybird, I have a lot of code something like this:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
someObject.write( baos );
statement.setBinaryStream( COLUMN_BLOB, new ByteArrayInputStream(
baos.getBytes() ) );
I'm sure I'm doing something stupid here, but it seems silly to have to
reallocate the bytes from "baos" then copy then over to the buffer in
"bais". In the past, I've just reimplemented these to Stream classes to
be able to reference each other's buffers but there must be an easier
way to do it.
TIA,
Robert