Java Code Examples for org.agrona.BufferUtil#boundsCheck()

The following examples show how to use org.agrona.BufferUtil#boundsCheck() . 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: MappedResizeableBuffer.java    From agrona with Apache License 2.0 6 votes vote down vote up
public void getBytes(final long index, final ByteBuffer dstBuffer, final int length)
{
    final int dstOffset = dstBuffer.position();
    if (SHOULD_BOUNDS_CHECK)
    {
        boundsCheck0(index, length);
        BufferUtil.boundsCheck(dstBuffer, dstOffset, length);
    }

    final byte[] dstByteArray;
    final long dstBaseOffset;
    if (dstBuffer.isDirect())
    {
        dstByteArray = null;
        dstBaseOffset = address(dstBuffer);
    }
    else
    {
        dstByteArray = array(dstBuffer);
        dstBaseOffset = ARRAY_BASE_OFFSET + arrayOffset(dstBuffer);
    }

    UNSAFE.copyMemory(null, addressOffset + index, dstByteArray, dstBaseOffset + dstOffset, length);
    dstBuffer.position(dstBuffer.position() + length);
}
 
Example 2
Source File: MappedResizeableBuffer.java    From agrona with Apache License 2.0 6 votes vote down vote up
public void putBytes(final long index, final ByteBuffer srcBuffer, final long srcIndex, final int length)
{
    if (SHOULD_BOUNDS_CHECK)
    {
        boundsCheck0(index, length);
        BufferUtil.boundsCheck(srcBuffer, srcIndex, length);
    }

    final byte[] srcByteArray;
    final long srcBaseOffset;
    if (srcBuffer.isDirect())
    {
        srcByteArray = null;
        srcBaseOffset = address(srcBuffer);
    }
    else
    {
        srcByteArray = array(srcBuffer);
        srcBaseOffset = ARRAY_BASE_OFFSET + arrayOffset(srcBuffer);
    }

    UNSAFE.copyMemory(srcByteArray, srcBaseOffset + srcIndex, null, addressOffset + index, length);
}
 
Example 3
Source File: MappedResizeableBuffer.java    From agrona with Apache License 2.0 5 votes vote down vote up
public void getBytes(final long index, final byte[] dst, final long offset, final int length)
{
    if (SHOULD_BOUNDS_CHECK)
    {
        boundsCheck0(index, length);
        BufferUtil.boundsCheck(dst, offset, length);
    }

    UNSAFE.copyMemory(null, addressOffset + index, dst, ARRAY_BASE_OFFSET + offset, length);
}
 
Example 4
Source File: MappedResizeableBuffer.java    From agrona with Apache License 2.0 5 votes vote down vote up
public void putBytes(final long index, final byte[] src, final long offset, final int length)
{
    if (SHOULD_BOUNDS_CHECK)
    {
        boundsCheck0(index, length);
        BufferUtil.boundsCheck(src, offset, length);
    }

    UNSAFE.copyMemory(src, ARRAY_BASE_OFFSET + offset, null, addressOffset + index, length);
}
 
Example 5
Source File: MappedResizeableBuffer.java    From agrona with Apache License 2.0 5 votes vote down vote up
public void putBytes(final long index, final ByteBuffer srcBuffer, final int length)
{
    final int srcIndex = srcBuffer.position();
    if (SHOULD_BOUNDS_CHECK)
    {
        boundsCheck0(index, length);
        BufferUtil.boundsCheck(srcBuffer, srcIndex, length);
    }

    putBytes(index, srcBuffer, srcIndex, length);
    srcBuffer.position(srcIndex + length);
}