Github user clebertsuconic commented on a diff in the pull request:
https://github.com/apache/activemq-artemis/pull/1970#discussion_r176507140
--- Diff:
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
---
@@ -213,6 +218,63 @@ public ActiveMQBuffer getReadOnlyBodyBuffer() {
return new ChannelBufferWrapper(buffer.slice(BODY_OFFSET,
endOfBodyPosition - BUFFER_HEADER_SPACE).setIndex(0, endOfBodyPosition -
BUFFER_HEADER_SPACE).asReadOnly());
}
+ /**
+ * This will return the proper buffer to represent the data of the
Message. If compressed it will decompress.
+ * If large, it will read from the file or streaming.
+ * @return
+ * @throws ActiveMQException
+ */
+ @Override
+ public ActiveMQBuffer getDataBuffer() {
+
+ ActiveMQBuffer buffer;
+
+ try {
+ if (isLargeMessage()) {
+ LargeBodyEncoder encoder = getBodyEncoder();
+ encoder.open();
+ int bodySize = (int) encoder.getLargeBodySize();
+
+ buffer = new
ChannelBufferWrapper(UnpooledByteBufAllocator.DEFAULT.heapBuffer(bodySize));
+
+ encoder.encode(buffer, bodySize);
+ encoder.close();
+ } else {
+ buffer = getReadOnlyBodyBuffer();
+ }
+
+ if
(Boolean.TRUE.equals(getBooleanProperty(Message.HDR_LARGE_COMPRESSED))) {
+ buffer = inflate(buffer);
+ }
+ } catch (Exception e) {
+ ActiveMQIOErrorException e2 = new ActiveMQIOErrorException();
+ e2.initCause(e);
+ logger.warn(e.getMessage(), e);
+ return getReadOnlyBodyBuffer();
+ }
+
+ return buffer;
+ }
+
+ private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws
DataFormatException {
+ int bytesToRead = buffer.readableBytes();
+ Inflater inflater = new Inflater();
+
inflater.setInput(ByteUtil.getActiveArray(buffer.readBytes(bytesToRead).toByteBuffer()));
--- End diff --
It is. Unless you want to refactor it and implement proper inflated over
the buffer for an edge case.
This is just bringing code that is on stomp only to other protocols.
---