Buffering ChannelBuffers

David Hoyt dhoyt at llnl.gov
Fri May 22 14:26:10 EDT 2009


If there's a way I can continuously add to the InputStream as chunks come
in, then I could process my InputStream asynchronously too.

I did consider, btw, just using a list and adding each channelbuffer to that
- but I was hoping there would be a better or more efficient way or
something else inside the API that already does it.

 

From: netty-users-bounces at lists.jboss.org
[mailto:netty-users-bounces at lists.jboss.org] On Behalf Of David Hoyt
Sent: Friday, May 22, 2009 11:21 AM
To: netty-users at lists.jboss.org
Subject: Buffering ChannelBuffers

 

Hello,

So here's my problem - I need to buffer all my incoming data in memory until
the connection is closed and then create a java.io.InputStream that
represents all that data that I can then pass on. How do you suggest doing
that?

I looked at using a CompositeChannelBuffer, but I can't continually add
ChannelBuffers as they come in. With CompositeChannelBuffer (and
ChannelBuffers.wrappedBuffer(.)), you have to have all the ChannelBuffers up
front (there is no "addChannelBuffer() method on CompositeChannelBuffer).
Once I have all the data, I see that I can create a
ChannelBufferInputStream.

 

So my code should proceed as follows:

1. Connection is made with server

2. File is downloaded asynchronously

    a. As the file is downloaded in chunks, put each chunk (ChannelBuffer)
into a CompositeChannelBuffer or some other container

3. When file is done or the connection closes, create an InputStream from
the buffered data

4. Process the InputStream normally

 

My main problem is figuring out 2a. I could use some help since I'm still
learning the netty API.

Thanks!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20090522/0d3eea21/attachment.html 


More information about the netty-users mailing list