vadimiron
vadimiron

Reputation: 219

netty: get OutputStream for writing

Im starting with netty and need some help.

I dont understand, how can i get the OutputStream of the channel to write in. I have already an UpstreamHandler (decoder), that reads a Request and decodes it - now i would like to write back (an answer for the connected client). I can write a String (from examples from netty site), but i would like to write directly to some OutputStream (my busines logic method has an OutpuStream as parameter, to which data is written).

How can i do it with netty?

Upvotes: 2

Views: 2021

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23567

In Netty you use "Channel.write(..)" to write data back to the client. If you really need to write to an OutputStream you could do it with:

ChannelBufferOutputStream out = new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer());
yourObject.handle(out);
Channel.write(out.buffer());

An other approach would be to write an OutputStream that wraps an Channel.

Upvotes: 3

Related Questions