Q&A with Trustin Lee - How would I splice things with ChannelBuffer(s) ?
Trustin Lee
tlee at redhat.com
Tue Dec 2 20:34:47 EST 2008
Thanks fdev for sharing this for community! :)
Cheers,
Trustin
On Tue, Dec 02, 2008 at 03:34:08PM +0900, Flash Developer wrote:
> 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!
--
Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
--
what we call human nature in actuality is human habit
--
http://gleamynode.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20081203/bc0d4341/attachment.bin
More information about the netty-users
mailing list