From 2c7c81ca9ea305ff3e34e4f0158ffbb46550dec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 14 Sep 2016 20:53:27 +0300 Subject: [PATCH] STOMP frame encode: Use fixed buffers --- .../core/protocol/stomp/StompFrame.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java index 044b2dbd8f..5dd74f5c84 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java @@ -91,15 +91,10 @@ public class StompFrame { public ActiveMQBuffer toActiveMQBuffer() throws Exception { if (buffer == null) { - if (bytesBody != null) { - buffer = ActiveMQBuffers.dynamicBuffer(bytesBody.length + 512); - } - else { - buffer = ActiveMQBuffers.dynamicBuffer(512); - } - if (isPing()) { - buffer.writeByte((byte) 10); + buffer = ActiveMQBuffers.fixedBuffer(1); + buffer.writeByte((byte)10); + size = buffer.writerIndex(); return buffer; } @@ -117,7 +112,12 @@ public class StompFrame { // Add a newline to separate the headers from the content. head.append(Stomp.NEWLINE); - buffer.writeBytes(head.toString().getBytes(StandardCharsets.UTF_8)); + byte[] headBytes = head.toString().getBytes(StandardCharsets.UTF_8); + int bodyLength = (bytesBody == null) ? 0 : bytesBody.length; + + buffer = ActiveMQBuffers.fixedBuffer(headBytes.length + bodyLength + END_OF_FRAME.length); + + buffer.writeBytes(headBytes); if (bytesBody != null) { buffer.writeBytes(bytesBody); }