Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bd9a8808 authored by Gabriel Landais's avatar Gabriel Landais
Browse files

Multiple frames on a connection

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/gazelle-proxy/trunk@26338 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 3d9e53f3
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,12 @@ import org.openhealthtools.openatna.syslog.SyslogMessageFactory;
class SyslogFrameDecoder extends FrameDecoder {
private static final int STATUS_SIZE = 0;
private static final int STATUS_READ = 1;
private static final int STATUS_END = 2;
private static final int STATUS_INIT = 0;
private static final int STATUS_SIZE = 1;
private static final int STATUS_READ = 2;
private int status = STATUS_SIZE;
private StringBuffer messageSizeBuffer = new StringBuffer();
private int status = STATUS_INIT;
private StringBuffer messageSizeBuffer = null;
private int messageSize;
private ByteArrayOutputStream currentFrame = null;
......@@ -25,12 +25,17 @@ class SyslogFrameDecoder extends FrameDecoder {
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
while (buffer.readableBytes() > 0) {
byte readByte = buffer.readByte();
if (status == STATUS_INIT) {
messageSizeBuffer = new StringBuffer();
currentFrame = new ByteArrayOutputStream();
}
switch (status) {
case STATUS_SIZE:
if (readByte == 32) {
status = STATUS_READ;
messageSize = Integer.parseInt(messageSizeBuffer.toString());
currentFrame = new ByteArrayOutputStream();
} else {
char c = (char) readByte;
messageSizeBuffer.append(c);
......@@ -38,7 +43,7 @@ class SyslogFrameDecoder extends FrameDecoder {
break;
case STATUS_READ:
if (currentFrame.size() == messageSize) {
status = STATUS_END;
status = STATUS_INIT;
byte[] bytes = currentFrame.toByteArray();
String rawMessage = new String(bytes, "UTF-8");
SyslogMessage<?> syslogMessage = SyslogMessageFactory.getFactory().read(
......@@ -47,8 +52,6 @@ class SyslogFrameDecoder extends FrameDecoder {
}
currentFrame.write(readByte);
break;
case STATUS_END:
return null;
default:
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment