diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/SimpleBytes.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/SimpleBytes.java index 3d0fddc12d..474ea3d97c 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/SimpleBytes.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/SimpleBytes.java @@ -35,10 +35,8 @@ public class SimpleBytes public String getString() { if (index == 0) return ""; - byte[] realData = new byte[index]; - System.arraycopy(contents, 0, realData, 0, realData.length); - return new String(realData, StandardCharsets.UTF_8); + return new String(contents, 0, index, StandardCharsets.UTF_8); } public void reset() diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java index d0c13d1f1d..57ecbb2893 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java @@ -312,11 +312,7 @@ public class StompDecoder { if (inHeaderName) { - byte[] data = new byte[pos - headerBytesCopyStart - 1]; - - System.arraycopy(workingBuffer, headerBytesCopyStart, data, 0, data.length); - - headerName = new String(data); + headerName = new String(workingBuffer, headerBytesCopyStart, pos - headerBytesCopyStart - 1); inHeaderName = false; @@ -339,11 +335,7 @@ public class StompDecoder break outer; } - byte[] data = new byte[pos - headerBytesCopyStart - 1]; - - System.arraycopy(workingBuffer, headerBytesCopyStart, data, 0, data.length); - - String headerValue = new String(data); + String headerValue = new String(workingBuffer, headerBytesCopyStart, pos - headerBytesCopyStart - 1); headers.put(headerName, headerValue); 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 cb6ede5b75..2958c987e4 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 @@ -229,10 +229,7 @@ public class StompFrame iBuffer++; } - char[] total = new char[iBuffer]; - System.arraycopy(buffer, 0, total, 0, iBuffer); - - return new String(total); + return new String(buffer, 0, iBuffer); } public void setBody(String body)