Subject | RE: [Firebird-Java] OT - Stream Question |
---|---|
Author | Robert DiFalco |
Post date | 2003-06-11T19:47:17Z |
Just to give more definition, what I usually do is this:
public class SharedByteArrayOutputStream extends ByteArrayOutputStream
{
....
public ByteArrayInputStream asInputStream()
{
return new InputStream( buf, count );
}
}
Then I do this:
SharedByteArrayOutputStream baos = new SharedByteArrayOutputStream();
someObject.write( baos );
statement.setBinaryStream( COLUMN_BLOB, baos.asInputStream() );
I'm not really crazy about this because I have to use the protected
fields "buf" and "count" from ByteArrayOutputStream.
Any suggestions are appreciated.
R.
-----Original Message-----
From: Robert DiFalco
Sent: Wednesday, June 11, 2003 12:35 PM
To: Firebird-Java@yahoogroups.com
Subject: [Firebird-Java] OT - Stream Question
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
Yahoo! Groups Sponsor
To unsubscribe from this group, send an email to:
Firebird-Java-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
public class SharedByteArrayOutputStream extends ByteArrayOutputStream
{
....
public ByteArrayInputStream asInputStream()
{
return new InputStream( buf, count );
}
}
Then I do this:
SharedByteArrayOutputStream baos = new SharedByteArrayOutputStream();
someObject.write( baos );
statement.setBinaryStream( COLUMN_BLOB, baos.asInputStream() );
I'm not really crazy about this because I have to use the protected
fields "buf" and "count" from ByteArrayOutputStream.
Any suggestions are appreciated.
R.
-----Original Message-----
From: Robert DiFalco
Sent: Wednesday, June 11, 2003 12:35 PM
To: Firebird-Java@yahoogroups.com
Subject: [Firebird-Java] OT - Stream Question
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
Yahoo! Groups Sponsor
To unsubscribe from this group, send an email to:
Firebird-Java-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.