Commit 670875fe authored by Daryl Herzmann's avatar Daryl Herzmann Committed by akrherz

revert patch for OF-458, need to support Java 1.5


git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@12470 b35dd754-fafc-0310-a699-88a17e54d16e
parent d9dae4ec
...@@ -22,10 +22,8 @@ package org.jivesoftware.openfire.nio; ...@@ -22,10 +22,8 @@ package org.jivesoftware.openfire.nio;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction; import java.nio.charset.CodingErrorAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -116,8 +114,8 @@ class XMLLightweightParser { ...@@ -116,8 +114,8 @@ class XMLLightweightParser {
public XMLLightweightParser(String charset) { public XMLLightweightParser(String charset) {
encoder = Charset.forName(charset).newDecoder() encoder = Charset.forName(charset).newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE) .onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPLACE); .onUnmappableCharacter(CodingErrorAction.REPORT);
} }
/* /*
...@@ -182,23 +180,39 @@ class XMLLightweightParser { ...@@ -182,23 +180,39 @@ class XMLLightweightParser {
if (buffer.length() > maxBufferSize) { if (buffer.length() > maxBufferSize) {
throw new Exception("Stopped parsing never ending stanza"); throw new Exception("Stopped parsing never ending stanza");
} }
CharBuffer charBuffer = CharBuffer.allocate(byteBuffer.capacity()); CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
encoder.reset(); char[] buf = charBuffer.array();
CoderResult coderResult = encoder.decode(byteBuffer.buf(), charBuffer, false); int readByte = charBuffer.remaining();
char[] buf = Arrays.copyOf(charBuffer.array(), charBuffer.position());
int readChar = buf.length;
// Just return if nothing was read // Just return if nothing was read
if (readChar == 0) { if (readByte == 0) {
return; return;
} }
buffer.append(buf); // Verify if the last received byte is an incomplete double byte character
char lastChar = buf[readByte-1];
if (lastChar >= 0xfff0) {
if (Log.isDebugEnabled()) {
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--;
// Just return if nothing was read
if (readByte == 0) {
return;
}
}
buffer.append(buf, 0, readByte);
// Robot. // Robot.
char ch; char ch;
boolean isHighSurrogate = false; boolean isHighSurrogate = false;
for (int i = 0; i < readChar; i++) { for (int i = 0; i < readByte; i++) {
ch = buf[i]; ch = buf[i];
if (ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD && ch != 0x0) { if (ch < 0x20 && ch != 0x9 && ch != 0xA && ch != 0xD && ch != 0x0) {
//Unicode characters in the range 0x0000-0x001F other than 9, A, and D are not allowed in XML //Unicode characters in the range 0x0000-0x001F other than 9, A, and D are not allowed in XML
...@@ -229,7 +243,7 @@ class XMLLightweightParser { ...@@ -229,7 +243,7 @@ class XMLLightweightParser {
if (tailCount == head.length()) { if (tailCount == head.length()) {
// Close stanza found! // Close stanza found!
// Calculate the correct start,end position of the message into the buffer // Calculate the correct start,end position of the message into the buffer
int end = buffer.length() - readChar + (i + 1); int end = buffer.length() - readByte + (i + 1);
String msg = buffer.substring(startLastMsg, end); String msg = buffer.substring(startLastMsg, end);
// Add message to the list // Add message to the list
foundMsg(msg); foundMsg(msg);
...@@ -268,7 +282,7 @@ class XMLLightweightParser { ...@@ -268,7 +282,7 @@ class XMLLightweightParser {
status = XMLLightweightParser.OUTSIDE; status = XMLLightweightParser.OUTSIDE;
if (depth < 1) { if (depth < 1) {
// Found a tag in the form <tag /> // Found a tag in the form <tag />
int end = buffer.length() - readChar + (i + 1); int end = buffer.length() - readByte + (i + 1);
String msg = buffer.substring(startLastMsg, end); String msg = buffer.substring(startLastMsg, end);
// Add message to the list // Add message to the list
foundMsg(msg); foundMsg(msg);
...@@ -314,7 +328,7 @@ class XMLLightweightParser { ...@@ -314,7 +328,7 @@ class XMLLightweightParser {
if (insideRootTag && ("stream:stream>".equals(head.toString()) || if (insideRootTag && ("stream:stream>".equals(head.toString()) ||
("?xml>".equals(head.toString())) || ("flash:stream>".equals(head.toString())))) { ("?xml>".equals(head.toString())) || ("flash:stream>".equals(head.toString())))) {
// Found closing stream:stream // Found closing stream:stream
int end = buffer.length() - readChar + (i + 1); int end = buffer.length() - readByte + (i + 1);
// Skip LF, CR and other "weird" characters that could appear // Skip LF, CR and other "weird" characters that could appear
while (startLastMsg < end && '<' != buffer.charAt(startLastMsg)) { while (startLastMsg < end && '<' != buffer.charAt(startLastMsg)) {
startLastMsg++; startLastMsg++;
......
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