Github user franz1981 commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1970#discussion_r176494666
  
    --- 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();
    --- End diff --
    
    The `Inflater` should be part of the parameter in order to allow future API 
usage allowing it to be pooled (it is not a lightweight object)


---

Reply via email to