Java Code Examples for org.apache.qpid.proton.codec.ReadableBuffer#hasArray()

The following examples show how to use org.apache.qpid.proton.codec.ReadableBuffer#hasArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeliveryImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private byte[] copyContents(ReadableBuffer buffer)
{
    byte[] copy = new byte[buffer.remaining()];

    if (buffer.hasArray())
    {
        System.arraycopy(buffer.array(), buffer.arrayOffset() + buffer.position(), copy, 0, buffer.remaining());
        buffer.position(buffer.limit());
    }
    else
    {
        buffer.get(copy, 0, buffer.remaining());
    }

    return copy;
}
 
Example 2
Source File: Binary.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public static Binary create(ReadableBuffer buffer)
{
    if (buffer == null)
    {
        return null;
    }
    else if (!buffer.hasArray())
    {
        byte data[] = new byte [buffer.remaining()];
        ReadableBuffer dup = buffer.duplicate();
        dup.get(data);
        return new Binary(data);
    }
    else
    {
        return new Binary(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    }
}
 
Example 3
Source File: AMQPLargeMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void addBytes(ReadableBuffer data) throws Exception {

      // We need to parse the header on the first add,
      // as it will contain information if the message is durable or not
      if (header == null && largeBody.getStoredBodySize() <= 0) {
         parseHeader(data);
      }

      if (data.hasArray() && data.remaining() == data.array().length) {
         //System.out.println("Received " + data.array().length + "::" + ByteUtil.formatGroup(ByteUtil.bytesToHex(data.array()), 8, 16));
         largeBody.addBytes(data.array());
      } else {
         byte[] bytes = new byte[data.remaining()];
         data.get(bytes);
         //System.out.println("Finishing " + bytes.length + ByteUtil.formatGroup(ByteUtil.bytesToHex(bytes), 8, 16));
         largeBody.addBytes(bytes);
      }
   }
 
Example 4
Source File: FrameWriterBuffer.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void put(ReadableBuffer payload) {
    final int toCopy = payload.remaining();
    ensureRemaining(toCopy);

    if (payload.hasArray()) {
        System.arraycopy(payload.array(), payload.arrayOffset() + payload.position(), array, position, toCopy);
        payload.position(payload.position() + toCopy);
    } else {
        payload.get(array, position, toCopy);
    }

    position += toCopy;
}
 
Example 5
Source File: NettyWritable.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void put(ReadableBuffer buffer) {
   if (buffer.hasArray()) {
      nettyBuffer.writeBytes(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
   } else {
      nettyBuffer.writeBytes(buffer.byteBuffer());
   }
}