Class AbstractDemarcator

java.lang.Object
org.apache.nifi.stream.io.util.AbstractDemarcator
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
StreamDemarcator, TextLineDemarcator

abstract class AbstractDemarcator extends Object implements Closeable
Base class for implementing streaming demarcators.

NOTE: Not intended for multi-thread usage hence not Thread-safe.

  • Field Details

    • INIT_BUFFER_SIZE

      static final int INIT_BUFFER_SIZE
      See Also:
    • is

      private final InputStream is
    • initialBufferSize

      private final int initialBufferSize
    • maxDataSize

      private final int maxDataSize
    • buffer

      byte[] buffer
    • index

      int index
    • mark

      int mark
    • offset

      long offset
    • availableBytesLength

      int availableBytesLength
  • Constructor Details

    • AbstractDemarcator

      AbstractDemarcator(InputStream is, int maxDataSize)
      Constructs an instance of demarcator with provided InputStream and max buffer size. Each demarcated token must fit within max buffer size, otherwise the exception will be raised.
    • AbstractDemarcator

      AbstractDemarcator(InputStream is, int maxDataSize, int initialBufferSize)
      Constructs an instance of demarcator with provided InputStream and max buffer size and initial buffer size. Each demarcated token must fit within max buffer size, otherwise the exception will be raised.
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • fill

      void fill() throws IOException
      Will fill the current buffer from current 'index' position, expanding it and or shuffling it if necessary. If buffer exceeds max buffer size a TokenTooLargeException will be thrown.
      Throws:
      IOException - if unable to read from the stream
    • extractDataToken

      byte[] extractDataToken(int length) throws IOException
      Will extract data token of the provided length from the current buffer starting at the 'mark'.
      Throws:
      IOException
    • validate

      private void validate(InputStream is, int maxDataSize, int initialBufferSize)
      Validates prerequisites for constructor arguments