Class ReadableChannelWithLimitByDelimiter<A,X extends ReadableChannel<A>>

Type Parameters:
A -
X -
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, HasArrayOps<A>, ReadableChannel<A>, ReadableSource<A>

public class ReadableChannelWithLimitByDelimiter<A,X extends ReadableChannel<A>> extends ReadableChannelDecoratorBase<A,X>
Wrap a stream such that reading is cut off at the first delimiter (including it) after a certain position. Typically used to limit the stream to the first newline after a split. If the underlying channel's read method returns -2 it is interpreted as an end-of-block (EOB) marker. This class limits the stream on the first delimiter after EOB. This class hides any encountered block markers: Its read method either returns a positive non-zero integer for the number of bytes read or -1 if either the final delimiter has been reached or the underlying channel has been consumed.
  • Field Details

    • nextSplitOffset

      protected long nextSplitOffset
    • delimiter

      protected byte delimiter
    • isInEofState

      protected boolean isInEofState
    • bytesRead

      protected long bytesRead
    • excessBuffer

      protected A excessBuffer
    • getPosition

      protected GetPosition getPosition
    • isBlockMode

      protected boolean isBlockMode
  • Constructor Details

    • ReadableChannelWithLimitByDelimiter

      public ReadableChannelWithLimitByDelimiter(X delegate, GetPosition getPosition, boolean isBlockMode, byte delimiter, long nextSplitOffset)
      Parameters:
      delegate -
      getPosition -
      isBlockMode - If true then expect block boundaries to be advertised with -2 results of reads.
      delimiter -
      nextSplitOffset -
  • Method Details

    • read

      public int read(A array, int position, int length) throws IOException
      Description copied from interface: ReadableSource
      Read method following the usual InputStream protocol.
      Specified by:
      read in interface ReadableSource<A>
      Overrides:
      read in class ReadableChannelDecoratorBase<A,X extends ReadableChannel<A>>
      Parameters:
      array - The array into which to put the read data
      position - Offset into array where to start writing
      length - Maximum number of items to read.
      Returns:
      The number of items read. Return -1 if end of data was reached, and 0 iff length was 0.
      Throws:
      IOException
    • getBytesRead

      public long getBytesRead()