diff --git a/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java b/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java index 4f93056..0339e6c 100644 --- a/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java +++ b/src/java/org/jivesoftware/multiplexer/net/XMLLightweightParser.java @@ -2,7 +2,7 @@ * $Revision: $ * $Date: $ * - * Copyright (C) 2007 Jive Software. All rights reserved. + * Copyright (C) 2008 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. @@ -11,6 +11,7 @@ package org.jivesoftware.multiplexer.net; import org.apache.mina.common.ByteBuffer; +import org.jivesoftware.util.Log; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -81,7 +82,6 @@ protected boolean insideChildrenTag = false; - ByteBuffer byteBuffer; Charset encoder; public XMLLightweightParser(String charset) { @@ -154,6 +154,18 @@ 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) <= ' ') { diff --git a/src/java/org/jivesoftware/multiplexer/net/XMPPDecoder.java b/src/java/org/jivesoftware/multiplexer/net/XMPPDecoder.java index 3d1fe97..e50a916 100644 --- a/src/java/org/jivesoftware/multiplexer/net/XMPPDecoder.java +++ b/src/java/org/jivesoftware/multiplexer/net/XMPPDecoder.java @@ -3,7 +3,7 @@ * $Revision: $ * $Date: $ * - * Copyright (C) 2006 Jive Software. All rights reserved. + * Copyright (C) 2008 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. @@ -36,6 +36,6 @@ out.write(stanza); } } - return true; + return !in.hasRemaining(); } }