aeron-client/src/main/java/io/aeron/Image.java
public long controlledPeek(
        final long initialPosition, final ControlledFragmentHandler handler, final long limitPosition)
    {
        if (isClosed)
        {
            return 0;
        }

        validatePosition(initialPosition);

        int initialOffset = (int)initialPosition & termLengthMask;
        int offset = initialOffset;
        long position = initialPosition;
        final UnsafeBuffer termBuffer = activeTermBuffer(initialPosition);
        final int capacity = termBuffer.capacity();
        final Header header = this.header;
        header.buffer(termBuffer);
        long resultingPosition = initialPosition;

        try
        {
            while (position < limitPosition && offset < capacity)
            {
                final int length = frameLengthVolatile(termBuffer, offset);
                if (length <= 0)
                {
                    break;
                }

                final int frameOffset = offset;
                final int alignedLength = BitUtil.align(length, FRAME_ALIGNMENT);
                offset += alignedLength;

                if (isPaddingFrame(termBuffer, frameOffset))
                {
                    position += (offset - initialOffset);
                    initialOffset = offset;
                    resultingPosition = position;

                    continue;
                }

                header.offset(frameOffset);

                final Action action = handler.onFragment(
                    termBuffer, frameOffset + HEADER_LENGTH, length - HEADER_LENGTH, header);

                if (action == ABORT)
                {
                    break;
                }

                position += (offset - initialOffset);
                initialOffset = offset;

                if ((header.flags() & END_FRAG_FLAG) == END_FRAG_FLAG)
                {
                    resultingPosition = position;
                }

                if (action == BREAK)
                {
                    break;
                }
            }
        }
        catch (final Throwable t)
        {
            errorHandler.onError(t);
        }

        return resultingPosition;
    }
public long controlledPeek(
        final long initialPosition, final ControlledFragmentHandler handler, final long limitPosition)
    {
        if (isClosed)
        {
            return 0;
        }

        validatePosition(initialPosition);

        int initialOffset = (int)initialPosition & termLengthMask;
        int offset = initialOffset;
        long position = initialPosition;
        final UnsafeBuffer termBuffer = activeTermBuffer(initialPosition);
        final int capacity = termBuffer.capacity();
        final Header header = this.header;
        header.buffer(termBuffer);
        long resultingPosition = initialPosition;

        try
        {
            while (position < limitPosition && offset < capacity)
            {
                final int length = frameLengthVolatile(termBuffer, offset);
                if (length <= 0)
                {
                    break;
                }

                final int frameOffset = offset;
                final int alignedLength = BitUtil.align(length, FRAME_ALIGNMENT);
                offset += alignedLength;

                if (isPaddingFrame(termBuffer, frameOffset))
                {
                    position += (offset - initialOffset);
                    initialOffset = offset;
                    resultingPosition = position;

                    continue;
                }

                header.offset(frameOffset);

                final Action action = handler.onFragment(
                    termBuffer, frameOffset + HEADER_LENGTH, length - HEADER_LENGTH, header);

                if (action == ABORT)
                {
                    break;
                }

                position += (offset - initialOffset);
                initialOffset = offset;

                if ((header.flags() & END_FRAG_FLAG) == END_FRAG_FLAG)
                {
                    resultingPosition = position;
                }

                if (action == BREAK)
                {
                    break;
                }
            }
        }
        catch (final Throwable t)
        {
            errorHandler.onError(t);
        }

        return resultingPosition;
    }
public long controlledPeek ( final long initialPosition , final ControlledFragmentHandler handler , final long limitPosition ) { if ( isClosed ) { return 0 ; } validatePosition ( initialPosition ) ; int initialOffset = ( int ) initialPosition & termLengthMask ; int offset = initialOffset ; long position = initialPosition ; final UnsafeBuffer termBuffer = activeTermBuffer ( initialPosition ) ; final int capacity = termBuffer . capacity ( ) ; final Header header = this . header ; header . buffer ( termBuffer ) ; long resultingPosition = initialPosition ; try { while ( position < limitPosition && offset < capacity ) { final int length = frameLengthVolatile ( termBuffer , offset ) ; if ( length <= 0 ) { break ; } final int frameOffset = offset ; final int alignedLength = BitUtil . align ( length , FRAME_ALIGNMENT ) ; offset += alignedLength ; if ( isPaddingFrame ( termBuffer , frameOffset ) ) { position += ( offset - initialOffset ) ; initialOffset = offset ; resultingPosition = position ; continue ; } header . offset ( frameOffset ) ; final Action action = handler . onFragment ( termBuffer , frameOffset + HEADER_LENGTH , length - HEADER_LENGTH , header ) ; if ( action == ABORT ) { break ; } position += ( offset - initialOffset ) ; initialOffset = offset ; if ( ( header . flags ( ) & END_FRAG_FLAG ) == END_FRAG_FLAG ) { resultingPosition = position ; } if ( action == BREAK ) { break ; } } } catch ( final Throwable t ) { errorHandler . onError ( t ) ; } return resultingPosition ; }
Peek for new messages in a stream by scanning forward from an initial position. If new messages are found then
they will be delivered to the {@link ControlledFragmentHandler} up to a limited position.
<p>
Use a {@link ControlledFragmentAssembler} to assemble messages which span multiple fragments. Scans must also
start at the beginning of a message so that the assembler is reset.

@param initialPosition from which to peek forward.
@param handler         to which message fragments are delivered.
@param limitPosition   up to which can be scanned.
@return the resulting position after the scan terminates which is a complete message.
@see ControlledFragmentAssembler
@see ImageControlledFragmentAssembler
Peek for new messages in a stream by scanning forward from an initial position . If new messages are found then they will be delivered to the { @link ControlledFragmentHandler } up to a limited position . <p > Use a { @link ControlledFragmentAssembler } to assemble messages which span multiple fragments . Scans must also start at the beginning of a message so that the assembler is reset .