Class IonReaderLookaheadBuffer

  • All Implemented Interfaces:
    ReaderLookaheadBuffer

    public final class IonReaderLookaheadBuffer
    extends java.lang.Object
    Monitors an InputStream over binary Ion data to ensure enough data is available to be navigated successfully by a non-incremental IonReader.

    Error reporting: this wrapper reads the least amount of Ion data possible in order to determine whether a value is complete. As such, it will not raise any errors if invalid data exists anywhere outside the header of a top-level value. Any such invalid data will be detected as normal by the IonReader. In the few cases where this wrapper does detect an error (e.g. upon finding the illegal type 0xF), it will raise IonException.

    • Constructor Detail

      • IonReaderLookaheadBuffer

        public IonReaderLookaheadBuffer​(IonBufferConfiguration configuration,
                                        java.io.InputStream inputStream)
        Constructs a wrapper with the given configuration.
        Parameters:
        configuration - the configuration for the new instance.
        inputStream - an InputStream over binary Ion data.
    • Method Detail

      • fillInputHelper

        protected void fillInputHelper()
                                throws java.lang.Exception
        Implements the behavior described in ReaderLookaheadBuffer.fillInput(), except for clearing the mark.
        Throws:
        java.io.IOException - if thrown by the underlying input stream.
        java.lang.Exception - if thrown by a handler method.
      • moreDataRequired

        public boolean moreDataRequired()
        Description copied from interface: ReaderLookaheadBuffer
        Indicates whether more data must become present in the raw input stream before a successful call to IonReader.next() may be made to position the reader on the most-recently-buffered value.
        Returns:
        true if more data is required to complete the next top-level user value; otherwise, false.
      • rewindToValueStart

        public void rewindToValueStart()
        Rewinds to the start of the value currently buffered. Does not include any system values that may precede the value. This method is not called in conjunction with mark() / rewind(), which may be used if the caller wants to rewind to the start of any system values that precede the current value. This method may be used to re-read the current value and may only be called after IonReader.next() has been called on the current value; otherwise, the data representing any system values that precede the current value would be lost.
        Throws:
        java.lang.IllegalStateException - if there is no value currently buffered or if system value data would be lost as a result of calling this method before IonReader.next() was called.
      • fillInput

        public final void fillInput()
                             throws java.lang.Exception
        Description copied from interface: ReaderLookaheadBuffer
        If possible, fills the input pipe with enough bytes to enable one more successful call to IonReader.next() on the non-incremental reader attached to the pipe. If not enough bytes were available in the raw input stream to complete the next top-level user value, calling ReaderLookaheadBuffer.moreDataRequired() after this method returns will return `true`. In this case, this method must be called again before calling `IonReader.next()` to position the reader on this value. Otherwise, `moreDataRequired()` will return `false` and a call to `IonReader.next()` may be made to position the reader on this value. Implementations may throw `IonException` if invalid Ion data is detected. Implementations may define exceptional cases.
        Specified by:
        fillInput in interface ReaderLookaheadBuffer
        Throws:
        java.lang.Exception - if an IOException is thrown by the underlying InputStream.
      • available

        public final int available()
        Description copied from interface: ReaderLookaheadBuffer
        Indicates how many bytes are currently stored in the internal buffer. This can be used to detect whether calls to fillInput() are successfully retrieving data.
        Specified by:
        available in interface ReaderLookaheadBuffer
        Returns:
        The number of bytes waiting in the input buffer.
      • mark

        public final void mark()
        Marks the current read position in the underlying buffer. This mark remains valid only until the next call to ReaderLookaheadBuffer.fillInput().
        Throws:
        java.lang.IllegalStateException - if more data is required to complete a value.
      • rewind

        public final void rewind()
        Rewinds the underlying buffer to the mark.
        Throws:
        java.lang.IllegalStateException - if there is no valid mark.
        See Also:
        mark()
      • clearMark

        public final void clearMark()
        Clears the mark.
        See Also:
        mark()
      • getPipe

        protected java.io.InputStream getPipe()
        Returns:
        the underlying pipe.
      • getInput

        protected java.io.InputStream getInput()
        Returns:
        the underlying input.
      • startNewValue

        protected void startNewValue()
        Prepares for the start of a new value by clearing the isSkippingCurrentValue flag.
      • startSkippingValue

        protected void startSkippingValue()
                                   throws java.lang.Exception
        Start skipping the current value, if it is not already being skipped. This should be called when the value is determined to be oversize. This truncates the buffer to the end of the previous value, reclaiming the space.
        Throws:
        java.lang.Exception - if thrown by the event handler.
      • isSkippingCurrentValue

        protected boolean isSkippingCurrentValue()
        Indicates whether the current value is being skipped due to being oversized.
        Returns:
        true if the value is being skipped; otherwise, false.
      • getMaximumBufferSize

        protected int getMaximumBufferSize()
        Returns:
        the maximum size of the buffer.