You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by netsql <ce...@gmail.com> on 2006/04/29 19:04:00 UTC

Stream encoding of strings

I am reading a stream that is supposed to be utf-8.
I use IOUtils to decode and display.

In console and in swing window, it shows non printable charcters that look
to be 16 bit.  Any suggestions on how to go about being able to read the
stream and decode its parts?

tia,
.V

Re: Stream encoding of strings

Posted by peter royal <pr...@apache.org>.
On May 3, 2006, at 8:20 PM, netsql wrote:
> Can I just read the inputstream to a byte[], and close the stream  
> (I get the
> inputstream from StreamIoHandler) and then wrap the bytebuffer  
> arround it?
> And then read fields one by one?

Don't use the StreamIoHandler then, as that just takes the ByteBuffer  
and makes an InputStream out of it.. Just get at the raw ByteBuffer  
directly by implementing IoHandler.messageReceived().
-pete

-- 
proyal@apache.org - http://fotap.org/~osi



Re: Stream encoding of strings

Posted by netsql <ce...@gmail.com>.
Can I just read the inputstream to a byte[], and close the stream (I get the
inputstream from StreamIoHandler) and then wrap the bytebuffer arround it?
And then read fields one by one?
.V

On 5/3/06, peter royal <pr...@apache.org> wrote:
>
> On May 3, 2006, at 1:30 PM, netsql wrote:
> > How do I take an InputStream and put it into a butebuffer so that I
> > can read
> > the fileds?
>
> Copy your InputStream into a ByteArrayOutputStream, and then you can
> copy the resulting byte[] into a ByteBuffer.
>
> Of course, what are you trying to really accomplish?
> -pete
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>


--
v.cekvenich@yahoo.com

Re: Stream encoding of strings

Posted by netsql <ce...@gmail.com>.
I just did a wrap of byte[] from InputStream.
When I get a byte, followed by getShort, it does not move down the
"array/stream". Do I have to call position each time I move up and down the
field? ??

.V

On 5/3/06, peter royal <pr...@apache.org> wrote:
>
> On May 3, 2006, at 1:30 PM, netsql wrote:
> > How do I take an InputStream and put it into a butebuffer so that I
> > can read
> > the fileds?
>
> Copy your InputStream into a ByteArrayOutputStream, and then you can
> copy the resulting byte[] into a ByteBuffer.
>
> Of course, what are you trying to really accomplish?
> -pete
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>


--
v.cekvenich@yahoo.com

Re: Stream encoding of strings

Posted by netsql <ce...@gmail.com>.
Read a network stream sent by a device.
It's sending me data elements, like short, int, char[16] in little edian,
etc.

.V

On 5/3/06, peter royal <pr...@apache.org> wrote:
>
> On May 3, 2006, at 1:30 PM, netsql wrote:
> > How do I take an InputStream and put it into a butebuffer so that I
> > can read
> > the fileds?
>
> Copy your InputStream into a ByteArrayOutputStream, and then you can
> copy the resulting byte[] into a ByteBuffer.
>
> Of course, what are you trying to really accomplish?
> -pete
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>


--
v.cekvenich@yahoo.com

Re: Stream encoding of strings

Posted by peter royal <pr...@apache.org>.
On May 3, 2006, at 1:30 PM, netsql wrote:
> How do I take an InputStream and put it into a butebuffer so that I  
> can read
> the fileds?

Copy your InputStream into a ByteArrayOutputStream, and then you can  
copy the resulting byte[] into a ByteBuffer.

Of course, what are you trying to really accomplish?
-pete

-- 
proyal@apache.org - http://fotap.org/~osi



Re: Stream encoding of strings

Posted by netsql <ce...@gmail.com>.
Thx.
How do I take an InputStream and put it into a butebuffer so that I can read
the fileds?

tia,
.V


Hi,
>
> How are you using MINA? Which version of MINA? Please describe what
> you're doing and what the problem is in more detail if possible.
>
> MINA's ByteBuffer already contains code to convert bytes into Java
> strings so you shouldn't have to use IOUtils for this purpose. Have a
> look at
>
> http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/common/ByteBuffer.html#getString(java.nio.charset.CharsetDecoder)
>
> /Niklas
>



--
v.cekvenich@yahoo.com

Re: Stream encoding of strings

Posted by Niklas Therning <ni...@trillian.se>.
netsql wrote:
> I am reading a stream that is supposed to be utf-8.
> I use IOUtils to decode and display.
> 
> In console and in swing window, it shows non printable charcters that look
> to be 16 bit.  Any suggestions on how to go about being able to read the
> stream and decode its parts?
> 
> tia,
> .V
> 

Hi,

How are you using MINA? Which version of MINA? Please describe what
you're doing and what the problem is in more detail if possible.

MINA's ByteBuffer already contains code to convert bytes into Java
strings so you shouldn't have to use IOUtils for this purpose. Have a
look at
http://directory.apache.org/subprojects/mina/apidocs/org/apache/mina/common/ByteBuffer.html#getString(java.nio.charset.CharsetDecoder)

/Niklas