Conversion of ChannelBuffer to InputStream

MikeQ michaelquilleash at hotmail.com
Thu Aug 20 14:10:42 EDT 2009


Hi all,

I am looking at using Netty for the first time.  I am trying to build a
simple server that when a message is received a method of the form 

handleRequest( InputStream inputStream, OutputStream )

I'm not quite sure how to implement the InputStream part of this.  I want
the called code to "pull" data off the InputStream as and when it chooses to
rather than a callback handler pushing data continually.  (You could liken
it to comparing SAX with StAX in XML world).

I looked at the decoder/framing stuff but I don't want to buffer the whole
request in memory first as it may be very large, want to stream it off the
network as it arrives.  Similar for the response.

Is there a common/suitable method for making this conversion?  It seems that
I need something like the following.

- create an InputStream backed by some custom buffer
- on messageReceived() callback copy ChannelBuffer contents into the custom
buffer
- invoke the method with the InputStream
- the first messageReceived() may not contain all the data so subsequent
calls would need to push the new data behind the same InputStream to be
consumed by the client if necessary
- when the called code is finished it returns
- if there is still data buffered then the method is invoked again
- repeat until data buffer is empty, go back to waiting for a new
messageReceived() call

Is there anything out there that does the above?  Or should I just write
something from scratch?

If I need to write from scratch are there any recommendations?

- Can I just copy the ChannelBuffer references on each callback and queue
them somewhere?  Or do I need to drain the contents to a separate buffer
before messageReceived() returns?
- Do I need to use a OrderedMemoryAwareThreadPoolExecutor somewhere?  If so
where?

Thanks in advance for any help.

Cheers.
-- 
View this message in context: http://n2.nabble.com/Conversion-of-ChannelBuffer-to-InputStream-tp3480780p3480780.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list