Q&A with Trustin Lee - How would I splice things with ChannelBuffer(s) ?
Flash Developer
fdeveloper at gmail.com
Tue Dec 2 01:34:08 EST 2008
fdev:
I was wondering whether it's OK to pass around things as Strings (that
originate from a ChannelBuffer source),
or whether it's best to keep things as ChannelBuffer(s) for as long as possible?
trustin lee:
hmm.. from which perspective? performance, or flexibility?
fdev:
well, dare I say performance...? The issue is that eventually, I need
to find the <head> tag within an ICAP response
and inject things before/after it, so I think eventually, it has to be
converted to a java.lang.String and back, right?
trustin lee:
Ah OK.
If it's not a UTF-16 document, then I think it's safe to use
ChannelBuffer directly.
ChannelBuffer provides indexOf operation so you will be able to find
the <head> tag.
and you can create two slices from the channel buffer - one that ends
with the <head> tag and the other.
and then.. you could create a new ChannelBuffer which contains
something you want to inject.
Now you got three buffers
fdev:
ok, interesting...
trustin lee:
they can be combined into one buffer without memory copy.
fdev:
ah, ok, that's what I was looking for... how?
trustin lee:
.. using ChannelBuffers.wrappedBuffer(ChannelBuffer...)
fdev:
ah, ok, that's exactly what I was looking for. Thanks!
More information about the netty-users
mailing list