Search in sources :

Example 6 with SectionDecoderImpl

use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl in project qpid-broker-j by apache.

the class Message_1_0 method getContent.

@Override
public QpidByteBuffer getContent(final int offset, final int length) {
    if (getMessageMetaData().getVersion() == 0) {
        SectionDecoder sectionDecoder = new SectionDecoderImpl(DESCRIBED_TYPE_REGISTRY.getSectionDecoderRegistry());
        try {
            List<EncodingRetainingSection<?>> sections;
            // not just #getSize()
            try (QpidByteBuffer allSectionsContent = super.getContent(0, Integer.MAX_VALUE)) {
                sections = sectionDecoder.parseAll(allSectionsContent);
            }
            List<QpidByteBuffer> bodySectionContent = new ArrayList<>();
            for (final EncodingRetainingSection<?> section : sections) {
                if (section instanceof DataSection || section instanceof AmqpValueSection || section instanceof AmqpSequenceSection) {
                    bodySectionContent.add(section.getEncodedForm());
                }
                section.dispose();
            }
            try (QpidByteBuffer bodyContent = QpidByteBuffer.concatenate(bodySectionContent)) {
                bodySectionContent.forEach(QpidByteBuffer::dispose);
                return bodyContent.view(offset, length);
            }
        } catch (AmqpErrorException e) {
            throw new ConnectionScopedRuntimeException(e);
        }
    } else {
        return super.getContent(offset, length);
    }
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) AmqpSequenceSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) SectionDecoderImpl(org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection) SectionDecoder(org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoder)

Aggregations

SectionDecoderImpl (org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl)6 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)6 SectionDecoder (org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoder)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 ArrayList (java.util.ArrayList)2 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)2 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)2 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)2 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)2 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)2 ByteBuffer (java.nio.ByteBuffer)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MessageInstance (org.apache.qpid.server.message.MessageInstance)1 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)1 HeaderSection (org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection)1 EncodingRetaining (org.apache.qpid.server.protocol.v1_0.type.messaging.codec.EncodingRetaining)1 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)1