Hmmm. I thought of that. I tried to skip it by setting in.position(2) and
then in.position(1). But I still get an exception.
The funny thing is that the client is not sending a NULL anyway. It's a
simple String of XML text.
Is there a better way to convert from a byte buffer to a string? Some better
built in method maybe?
Regards.
--Arsalan
On 6/14/06, Niklas Therning <[EMAIL PROTECTED]> wrote:
Arsalan Zaidi wrote:
> Hi.
>
> The client is sending me a bunch of plain text data. All I want to do at
> this stage is print it out.
>
> In Decoder.java, I have:
>
> public void decode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput
> out) throws Exception
> {
> log.entering(this.getClass().getName(), "decode", new Object[]
> {session, in, out});
> log.info("in.limit = "+in.limit());
> log.info("in.position = "+in.position());
> log.info("in.capacity = "+in.capacity());
> log.info("in.toString = "+in.toString());
>
> String temp = in.getString(CharsetUtil.getDefaultCharset
().newDecoder());
> log.info("original temp = "+temp.length());
> }
>
> Which prints out the following. Notice that even though I'm getting
data, I
> can't print it out. The String temp is always empty. What am I doing
wrong?
> ...
getString(...) reads a NUL terminated string. From the log output it
seems like the first byte in the buffer is 00, aka NUL. Hence you'll get
an empty string from getString(...).
HTH
--
Niklas Therning
Software Architect
www.spamdrain.net