[jcifs] NIO: java.nio.ByteBuffer Question

Michael B Allen mba2000 at ioplex.com
Sat Sep 24 15:56:07 GMT 2005


On Sat, 24 Sep 2005 13:12:25 +0530
"Manoj" <mkumar at mantragroup.com> wrote:

> Dear Michael B Allen,
> 
>  
> 
> I have seen your message in jcifs regarding java nio ByteBuffer. I have a problem with ByteBuffers somewhat similar to yours, so I thought interacting with you will provide me some useful information to solve my problem. I am reading ByteBuffer from Socket Channel and later when I decode it, if that data has only normal characters I get the full data. But if that contains any special characters then I am not getting the full data after decoding it. Special characters here I mean like ______. I have used all the Decoders available. I also checked and conformed that I am getting the full data from socketchannel but decoding is not proper. If my ByteBuffer has a message like "Hi ______ user", I am getting only "______ user" and if I get a message like "Hi ______ user ____ boss" I am getting "______ user ____ boss". I am not getting data before first special character. Please help me by giving me your valuable suggestions.

This has nothing to do with ByteBuffer really. This is a simple character
encoding issue. You need to determine which character encoding is in your
buffer. Then I assume there is a way to somehow create a buffer that
understands what the underlying encoding is. Actually from glancing at
the documentation it appears that you need to use the Charset class to
get a CharsetDecoder with the correct encoding type. Then you can use
it's decode() method to convert the bytes in the ByteBuffer to chars in
the specified CharBuffer.

If you need further instruction I recommend the Java USENET groups or
forums at java.sun.com.

Mike


More information about the jcifs mailing list