STOMP frame encode: Use fixed buffers

This commit is contained in:
Ville Skyttä 2016-09-14 20:53:27 +03:00
parent 8e59cf4d5f
commit 2c7c81ca9e
1 changed files with 9 additions and 9 deletions

View File

@ -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);
}