Top Description Inners Fields Constructors Methods
com.amazon.ion.impl

pack-priv Class IonCursorBinary

extends Object
implements IonCursor
Class Inheritance
All Implemented Interfaces
com.amazon.ion.IonCursor, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
com.amazon.ion.impl.IonReaderContinuableCoreBinary
Imports
com.amazon.ion.BufferConfiguration, .IonBufferConfiguration, .IonException, .IonCursor, .IonType, .IvmNotificationConsumer, .SystemSymbols, java.io.ByteArrayInputStream, .EOFException, .IOException, .InputStream, java.nio.ByteBuffer

An IonCursor over binary Ion data, capable of buffering or skipping Ion values at any depth. Records byte indices of the value currently buffered, enabling parsers direct access to the bytes in the value's representation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
IonCursorBinary.CheckpointLocation

The kind of location at which `checkpoint` points.

private static class
IonCursorBinary.RefillableState

State only used when the cursor's data source is refillable and the cursor is in slow mode.

private static enum
IonCursorBinary.State

The state representing where the cursor left off after the previous operation.

Field Summary

Modifier and TypeField and Description
pack-priv final Marker
annotationSequenceMarker

Marker for the sequence of annotation symbol IDs on the current value.

pack-priv byte[]
buffer

The buffer in which the cursor stores slices of the Ion stream.

pack-priv ByteBuffer
byteBuffer

A slice of the current buffer.

private long
checkpoint

The index of the first byte in the buffer that has not yet been successfully processed.

private IonCursorBinary.CheckpointLocation
checkpointLocation

Describes the byte at the `checkpoint` index.

private static final int
pack-priv int
containerIndex

The index of the current container in `containerStack`.

pack-priv Marker[]
containerStack

Stack to hold container info.

private final BufferConfiguration.DataHandler
dataHandler

The handler that will be notified when data is processed.

private static final int
pack-priv IonCursor.Event
event

The event that occurred as a result of the last call to any of the cursor's IonCursor methods.

pack-priv int
fieldSid

The field SID of the current value, if any.

private static final IonBufferConfiguration[]
FIXED_SIZE_CONFIGURATIONS

Cache of configurations for fixed-sized streams.

pack-priv boolean
hasAnnotations

Indicates whether the current value is annotated.

private static final int
pack-priv boolean
isSlowMode

Indicates whether the cursor is in slow mode.

pack-priv boolean
isValueIncomplete

Indicates whether the current value extends beyond the end of the buffer.

private static final int
private static final int
private static final int
private IvmNotificationConsumer
ivmConsumer

The consumer to be notified when Ion version markers are encountered.

private long
lastReportedByteTotal

The total number of bytes that had been consumed from the stream as of the last time progress was reported to the data handler.

pack-priv long
limit

The index at which the next byte received will be written.

private static final int
private static final int
private int
majorVersion

The major version of the Ion encoding currently being read.

private static final int
pack-priv int
minorVersion

The minor version of the Ion encoding currently being read.

private static final IvmNotificationConsumer
private long
offset

The index of the next byte in the buffer that is available to be read.

pack-priv Marker
parent

The Marker representing the parent container of the current value.

private long
peekIndex

The index of the next byte to be read from the buffer.

private IonCursorBinary.RefillableState
refillableState

Holds information necessary for reading from refillable input.

private static final int
private final long
startOffset

The start offset into the user-provided byte array, or 0 if the user provided an InputStream.

private static final IonCursorBinary.RefillableState
TERMINATED_STATE

Dummy state that indicates the cursor has been terminated and that additional API calls will have no effect.

private IonTypeID[]
typeIds

The set of type IDs to use for Ion version currently active in the stream.

private static final int
pack-priv final Marker
valueMarker

Marker representing the current value.

pack-priv long
valuePreHeaderIndex

The index of the first byte in the header of the value at which the reader is currently positioned.

pack-priv IonTypeID
valueTid

Type ID for the current value.

Constructor Summary

AccessConstructor and Description
pack-priv
IonCursorBinary(final IonBufferConfiguration
the configuration to use. The buffer size and oversized value configuration are unused, as the given buffer is used directly.
configuration
,
byte[]
the byte array containing the bytes to read.
buffer
,
int
the offset into the byte array at which the first byte of Ion data begins.
offset
,
int
the number of bytes to be read from the byte array.
length
)

Constructs a new fixed (non-refillable) cursor from the given byte array.

pack-priv
IonCursorBinary(IonBufferConfiguration
the configuration to use.
configuration
,
InputStream inputStream, byte[]
the byte array containing the bytes already read (often the IVM).
alreadyRead
,
int
the offset into `alreadyRead` at which the first byte that was already read exists.
alreadyReadOff
,
int
the number of bytes already read from `alreadyRead`.
alreadyReadLen
)

Constructs a refillable cursor from the given input stream.

Method Summary

Modifier and TypeMethod and Description
private long

Returns:

the number of bytes available in the buffer after the given index.
availableAt
(long
a byte index in the buffer.
index
)

private long

Returns:

the end index of the value or NOP pad.
calculateEndIndex_1_0
(IonTypeID
the type ID of the value.
valueTid
,
boolean
true if the value is annotated.
isAnnotated
)

Calculates the end index for the given type ID and sets `event` based on the type of value encountered, if any.

private long
calculateEndIndex_1_1(IonTypeID valueTid, boolean isAnnotated)

private boolean

Returns:

true if the end of the current container has been reached; otherwise, false.
checkContainerEnd
()

Determines whether the cursor has reached the end of the current container.

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public IonCursor.Event
endStream()

Implements com.amazon.ion.IonCursor.endStream.

Causes the cursor to force completion of the value on which it is currently positioned, if any.

private boolean

Returns:

true if the buffer has sufficient capacity; otherwise, false.
ensureCapacity
(long
the minimum number of additional bytes to buffer.
minimumNumberOfBytesRequired
)

Ensures that there is space for at least 'minimumNumberOfBytesRequired' additional bytes in the buffer, growing the buffer if necessary.

private boolean

Returns:

false if not enough bytes were available in the stream to satisfy the request; otherwise, true.
fillAt
(long
the index after which to fill.
index
,
long
the number of bytes after `index` that need to be present.
numberOfBytes
)

Attempts to fill the buffer so that it contains at least `numberOfBytes` after `index`.

public IonCursor.Event
fillValue()

Implements com.amazon.ion.IonCursor.fillValue.

Buffers the entirety of the value on which the cursor is currently positioned.

private long

Returns:

the number of bytes that can be written at the end of the buffer.
freeSpaceAt
(long index)

public IonCursor.Event
getCurrentEvent()

Implements com.amazon.ion.IonCursor.getCurrentEvent.

Conveys the result of the previous operation.

private static BufferConfiguration.DataHandler

Returns:

the given configuration's DataHandler, or null if that DataHandler is a no-op.
getDataHandler
(IonBufferConfiguration configuration)

private static IonBufferConfiguration

Returns:

a fixed IonBufferConfiguration.
getFixedSizeConfigurationFor
(ByteArrayInputStream
the stream.
inputStream
,
int
the number of bytes already read from the stream. The configuration provided will allow enough space for these bytes.
alreadyReadLen
)

Provides a fixed-size buffer configuration suitable for the given ByteArrayInputStream.

public int
public int
pack-priv long

Returns:

the total number of bytes read since the stream began.
getTotalOffset
()

pack-priv Marker
private void
growContainerStack()

Doubles the size of the cursor's container stack.

public boolean
private boolean

Returns:

true if the cursor is expecting more data in order to complete a token; otherwise, false.
isAwaitingMoreData
()

pack-priv boolean
private static int

Returns:

the exponent of the next power of two greater than or equal to the given number.
logBase2
(int
a non-negative number.
value
)

private void
moveBytesToStartOfBuffer(byte[]
the destination buffer, which may be 'buffer' itself or a new buffer.
destinationBuffer
,
int fromIndex)

Moves all buffered (but not yet read) bytes from 'buffer' to the destination buffer.

pack-priv static int

Returns:

the next power of two greater than or equal to the given number.
nextPowerOfTwo
(int
a non-negative number
value
)

public IonCursor.Event
nextValue()

Implements com.amazon.ion.IonCursor.nextValue.

Advances the cursor to the next value, skipping the current value (if any).

private void
prohibitEmptyOrderedStruct_1_0(Marker
the marker for the value to check.
marker
)

Throws if the given marker represents an empty ordered struct, which is prohibited by the Ion 1.0 specification.

private void
pushContainer()

Push a Marker representing the current container onto the stack.

private int

Returns:

the next byte, or -1 if the stream is at its end.
readByteWithoutBuffering
()

Reads a single byte without adding it to the buffer.

private void
readIvm()

Reads the final three bytes of an IVM.

private long

Returns:

the shortfall between the number of bytes that were filled and the minimum number requested. If less than 1, then at least `minimumNumberOfBytesRequired` were filled.
refill
(long
the minimum number of bytes requested to fill the current value.
minimumNumberOfBytesRequired
)

Attempts to fill the buffer with up to the requested number of additional bytes.

public void
pack-priv void
private void
reportConsumedData()

Reports the total number of bytes consumed from the stream since the last report, up to the current `peekIndex`.

private void
reset()

Resets state specific to the current value.

private void
resumeSlowMode()

Puts the cursor back in slow mode.

private void
private void
seekPastOversizedValue()

Seeks past an oversized value.

private void
setCheckpoint(IonCursorBinary.CheckpointLocation
the type of checkpoint location. Must not be BEFORE_UNANNOTATED_TYPE_ID.
location
)

Sets `checkpoint` to the current `peekIndex`, which is at the given type of location.

private void
setCheckpointBeforeUnannotatedTypeId()

Sets `checkpoint` to the current `peekIndex`, which must be before an unannotated type ID, and seeks the buffer to that point.

private void
setMarker(long
the value's end index.
endIndex
,
Marker
the marker to set.
markerToSet
)

Validates and sets the given marker, which must fit within its parent container (if applicable).

private void
shiftContainerEnds(long
the amount to shift left.
shiftAmount
)

Shift all active container end indices left by the given amount.

private void
shiftIndicesLeft(int
the amount to shift left.
shiftAmount
)

Shift all indices left by the given amount.

pack-priv boolean
pack-priv void
slice(long
the offset at which the slice will begin.
offset
,
long
the slice's limit.
limit
,
String
the Ion version ID for the slice, e.g. $ion_1_0 for Ion 1.0.
ionVersionId
)

Slices the buffer using the given offset and limit.

private boolean
private IonCursor.Event

Returns:

`event`, which conveys the result.
slowFillValue
()

Fills the buffer with the contents of the value on which the cursor is currently positioned, ensuring that enough bytes are available in the stream.

private boolean
private boolean

Returns:

true if the cursor is expecting more data in order to complete a token; otherwise, false.
slowIsAwaitingMoreData
()

private boolean
private boolean

Returns:

true if the cursor is ready; otherwise, false.
slowMakeBufferReady
()

Attempts to make the cursor READY by finishing the operation that was in progress last time the end of the stream was reached.

private void
slowNextToken()

Advances to the next token from the current checkpoint, seeking past the previous value if necessary, and ensuring that enough bytes are available in the stream.

private IonCursor.Event

Returns:

the result of the operation (e.g. START_SCALAR, END_CONTAINER).
slowNextValue
()

Advances to the next value, seeking past the previous if necessary, and ensuring enough bytes are available in the stream.

private IonCursor.Event

Returns:

the result of the operation (e.g. START_SCALAR, END_CONTAINER).
slowOverflowableNextToken
()

Advances to the next token, ensuring enough bytes are available in the stream and checking against size limits.

private int

Returns:

the byte, or -1 if the end of the stream has been reached.
slowPeekByte
()

Peek at the next byte from the stream, assuming it will be buffered unless the current value is being skipped.

private boolean

Returns:

true if there are not enough bytes in the stream to complete the value; otherwise, false.
slowReadAnnotationWrapperHeader_1_0
(IonTypeID
the type ID of the annotation wrapper.
valueTid
)

Reads the header of an annotation wrapper, ensuring enough data is available in the buffer.

private boolean
private int

Returns:

the byte, or -1 if the end of the stream has been reached.
slowReadByte
()

Read the next byte from the stream, ensuring the byte is buffered.

private boolean

Returns:

true if there are not enough bytes in the stream to complete the field SID; otherwise, false.
slowReadFieldName_1_0
()

Reads the field SID from the VarUInt starting at `peekIndex`, ensuring enough data is available in the buffer.

private boolean
private boolean

Returns:

false if enough bytes were buffered and the header belonged to an annotation wrapper or NOP pad; otherwise, true. When false, the caller should call the method again to read the header for the value that follows.
slowReadHeader
(final int
the type ID byte. This may be an annotation wrapper's type ID.
typeIdByte
,
final boolean
true if this type ID is on a value within an annotation wrapper; false if it is not.
isAnnotated
,
final Marker
the Marker to set with information parsed from the type ID and/or annotation wrapper header.
markerToSet
)

Reads a value or annotation wrapper header, ensuring enough bytes are buffered.

private boolean

Returns:

true if not enough data was available in the stream to complete the header; otherwise, false.
slowReadValueHeader
(IonTypeID
the type ID of the value. Must not be an annotation wrapper.
valueTid
,
boolean
true if this type ID is on a value within an annotation wrapper; false if it is not.
isAnnotated
,
Marker
the Marker to set with information parsed from the header.
markerToSet
)

Reads a value header, ensuring enough bytes are buffered.

private long

Returns:

the value.
slowReadVarUInt_1_0
()

Reads a VarUInt, ensuring enough data is available in the buffer.

private long
private boolean

Returns:

true if not enough data was available in the stream; otherwise, false.
slowSeek
(long
the number of bytes to seek from `offset`.
numberOfBytes
)

Seeks forward in the stream up to the requested number of bytes, from `offset`.

private boolean

Returns:

true if not enough data was available to seek past the NOP pad; otherwise, false.
slowSeekPastNopPad
(long
the length of the NOP pad.
valueLength
,
boolean
true if the NOP pad occurs within an annotation wrapper (which is illegal); otherwise, false.
isAnnotated
)

Validates and skips a NOP pad.

private boolean
private boolean
private boolean

Returns:

true if not enough data was available in the stream; otherwise, false.
slowSkipRemainingValueBytes
()

Skips past the remaining bytes in the current value, ensuring enough bytes are available in the stream.

private IonCursor.Event

Returns:

`event`, which conveys the result.
slowStepIntoContainer
()

Steps into the container on which the cursor is currently positioned, ensuring that the buffer is ready.

private IonCursor.Event

Returns:

`event`, which conveys the result.
slowStepOutOfContainer
()

Steps out of the container on which the cursor is currently positioned, ensuring that the buffer is ready and that enough bytes are available in the stream.

public IonCursor.Event
stepIntoContainer()

Implements com.amazon.ion.IonCursor.stepIntoContainer.

Steps the cursor into the container value on which the cursor is currently positioned.

public IonCursor.Event
stepOutOfContainer()

Implements com.amazon.ion.IonCursor.stepOutOfContainer.

Steps the cursor out of the current container, skipping any values in the container that may follow.

pack-priv void
terminate()

Terminates the cursor.

private boolean
private boolean

Returns:

true if the end of the container has been reached; otherwise, false.
uncheckedNextContainedToken
()

Advances to the next value within a container, checking for container end and consuming the field name, if any.

private boolean

Returns:

true if the next token was an Ion version marker or NOP pad; otherwise, false. If true, this method should be called again to advance to the following value.
uncheckedNextToken
()

Advances to the next token, seeking past the previous value if necessary.

private boolean

Returns:

true if the length of the wrapped value extends beyond the bytes currently buffered; otherwise, false.
uncheckedReadAnnotationWrapperHeader_1_0
(IonTypeID
the type ID of the annotation wrapper.
valueTid
)

Reads the header of an annotation wrapper.

private boolean
private void
private boolean

Returns:

false if the header belonged to NOP pad; otherwise, true. When false, the caller should call the method again to read the header for the value that follows.
uncheckedReadHeader
(final int
the type ID byte. This may be an annotation wrapper's type ID.
typeIdByte
,
final boolean
true if this type ID is on a value within an annotation wrapper; false if it is not.
isAnnotated
,
final Marker
the Marker to set with information parsed from the type ID and/or annotation wrapper header.
markerToSet
)

Reads a value header, consuming the value's annotation wrapper header, if any.

private long

Returns:

the value.
uncheckedReadVarUInt_1_0
(byte currentByte)

Reads a 2+ byte VarUInt, given the first byte.

private long
private void
uncheckedSeekPastNopPad(long
the endIndex of the NOP pad.
endIndex
,
boolean
true if the NOP pad occurs within an annotation wrapper (which is illegal); otherwise, false.
isAnnotated
)

Validates and skips a NOP pad.

private void
uncheckedStepIntoContainer()

Step into the current container.

private static void
validate(IonBufferConfiguration
the configuration to validate.
configuration
)

Validates the given configuration.

private void
validateAnnotationWrapperEndIndex(long
the annotated value's endIndex.
endIndex
)

Validates that an annotated value's endIndex matches the annotation wrapper's endIndex (which is contained in `valueMarker.endIndex`).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait