Commit 5e84ea54 authored by Chung's avatar Chung Committed by Christian Schudt

Fix unicode read on input

In the current read scheme for Openfire, it is possible that due
to variable width encoding that we sometimes only create a
string with a partial character.

This breaks the message text and causes encoding issues when read.

This change modifies the way the characters are
read to use an bytearrayoutputstream and
only do the string conversion once.

Since we only do the string creation once after the full
buffer is read, we no longer have encoding
issues with broken unicode characters.
parent 1d42ddf1
......@@ -396,7 +396,7 @@ public class HttpBindServlet extends HttpServlet {
class ReadListenerImpl implements ReadListener {
private final AsyncContext context;
private final StringBuilder buffer = new StringBuilder(512);
private final ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
private final String remoteAddress;
ReadListenerImpl(AsyncContext context) {
......@@ -413,14 +413,14 @@ public class HttpBindServlet extends HttpServlet {
byte b[] = new byte[1024];
int length;
while (inputStream.isReady() && (length = inputStream.read(b)) != -1) {
buffer.append(new String(b, 0, length, StandardCharsets.UTF_8));
outStream.write(b, 0, length);
}
}
@Override
public void onAllDataRead() throws IOException {
Log.trace("All data has been read from [" + remoteAddress + "]");
processContent(context, buffer.toString());
processContent(context, outStream.toString(StandardCharsets.UTF_8.name()));
}
@Override
......
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