mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Niklas Therning <nik...@trillian.se>
Subject Re: ByteBuffer to string
Date Tue, 13 Jun 2006 21:03:02 GMT
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

Mime
View raw message