Im a bit tired and i have to get up in about 5 hours but this is my
test which works without problems....
try {
ByteBuffer buf ;
String str2 ;
buf = ByteBuffer.allocate(1000);
buf.putString("<abc>1542</abc>\0",
Charset.forName("UTF-8").newEncoder() );
buf.flip();
CharsetDecoder decoder= Charset.forName("UTF-8").newDecoder();
str2 = buf.getString(decoder);
logger.info(str2);
buf.flip();
str2 = buf.getString(decoder);
logger.info(str2);
} catch(Exception ex) {
logger.info("blabla");
}
The buffer i had problems with came from a class which extends
CumulativeProtocolDecoder.
protected boolean doDecode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out) {
I also used the same teststring as the one i sended through the socket.
mmmm in my eyes its pretty strange and i have to look into it tomorow...
i removed the toStringg for this code and it does not give me any problems:
byte [] ba;
buf.flip();
ba = new byte[buf.remaining()];
buf.get(ba);
str = new String(ba, "UTF-8");
So if i want to be sure i do not run into any troubles with my server i
should reset the decoder before i use it?
PS : A stack trace could also help, and a hex dump of the buffer you
are trying to decode.
i looked at the buffer and it seemed okay.. How do i get the stuff you want?
(out of netbeans)
I know how to look at it but im unaware of how to easily copy/paste it... (im a
bit of a java noob also).