Class AbstractCloseableIteratorAsInputStream<T>

java.lang.Object
java.io.InputStream
io.servicetalk.concurrent.internal.AbstractCloseableIteratorAsInputStream<T>
Type Parameters:
T - Type of items emitted by the CloseableIterator.
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
CloseableIteratorBufferAsInputStream

public abstract class AbstractCloseableIteratorAsInputStream<T> extends InputStream
Conversion from a CloseableIterator to a InputStream given a Function to serialize to bytes.
  • Constructor Details

    • AbstractCloseableIteratorAsInputStream

      protected AbstractCloseableIteratorAsInputStream(CloseableIterator<T> source)
      Create a new instance.
      Parameters:
      source - The CloseableIterator providing data.
  • Method Details

    • leftOverReadableBytes

      protected abstract int leftOverReadableBytes()
      Get the number of readable bytes in the left over buffer.
      Returns:
      the number of readable bytes in the left over buffer.
    • leftOverReadBytes

      protected abstract void leftOverReadBytes(byte[] dst, int offset, int length)
      Read bytes from the left over buffer into b.
      Parameters:
      dst - The destination to read to.
      offset - The offset to read into for dst.
      length - The amount of bytes to read from the left over buffer.
    • hasLeftOver

      protected abstract boolean hasLeftOver()
      Determine if there are left over bytes buffered.
      Returns:
      true if there are left over bytes buffered.
    • leftOverCheckReset

      protected abstract void leftOverCheckReset()
      Check if the left over buffer needs to be reset.
    • leftOverReset

      protected abstract void leftOverReset()
      Reset the left over buffer.
    • nextLeftOver

      protected abstract void nextLeftOver(CloseableIterator<T> iterator)
      Read the next element from the Iterator.
      Parameters:
      iterator - The CloseableIterator to get the next element from.
    • leftOverReadSingleByte

      protected abstract byte leftOverReadSingleByte()
      Read a single byte from the left over buffer.
      Returns:
      a single byte from the left over buffer.
    • isClosed

      protected abstract boolean isClosed()
      Determine if close() has been called.
      Returns:
      true if close() has been called.
    • read

      public final int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • available

      public final int available()
      Overrides:
      available in class InputStream
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • markSupported

      public final boolean markSupported()
      Overrides:
      markSupported in class InputStream
    • read

      public final int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException