Commit 15cb434b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed reading of doublebyte characters. JM-1175

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9888 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4a685d18
......@@ -11,6 +11,7 @@
package org.jivesoftware.openfire.nio;
import org.apache.mina.common.ByteBuffer;
import org.jivesoftware.util.Log;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
......@@ -81,7 +82,6 @@ class XMLLightweightParser {
protected boolean insideChildrenTag = false;
ByteBuffer byteBuffer;
Charset encoder;
public XMLLightweightParser(String charset) {
......@@ -154,6 +154,18 @@ class XMLLightweightParser {
char[] buf = charBuffer.array();
int readByte = charBuffer.remaining();
// Verify if the last received byte is an incomplete double byte character
char lastChar = buf[readByte-1];
if (Character.isISOControl(lastChar) || lastChar >= 0xfff0) {
Log.debug("Waiting to get complete char: " + String.valueOf(buf));
// Rewind the position one place so the last byte stays in the buffer
// The missing byte should arrive in the next iteration. Once we have both
// of bytes we will have the correct character
byteBuffer.position(byteBuffer.position()-1);
// Decrease the number of bytes read by one
readByte--;
}
buffer.append(buf, 0, readByte);
// Do nothing if the buffer only contains white spaces
if (buffer.charAt(0) <= ' ' && buffer.charAt(buffer.length()-1) <= ' ') {
......
......@@ -35,6 +35,6 @@ public class XMPPDecoder extends CumulativeProtocolDecoder {
out.write(stanza);
}
}
return true;
return !in.hasRemaining();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment