Class AbstractCloseableIteratorAsInputStream<T>

  • Type Parameters:
    T - Type of items emitted by the CloseableIterator.
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    CloseableIteratorBufferAsInputStream

    public abstract class AbstractCloseableIteratorAsInputStream<T>
    extends java.io.InputStream
    Conversion from a CloseableIterator to a InputStream given a Function to serialize to bytes.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      protected abstract boolean hasLeftOver()
      Determine if there are left over bytes buffered.
      protected abstract boolean isClosed()
      Determine if close() has been called.
      protected abstract void leftOverCheckReset()
      Check if the left over buffer needs to be reset.
      protected abstract int leftOverReadableBytes()
      Get the number of readable bytes in the left over buffer.
      protected abstract void leftOverReadBytes​(byte[] dst, int offset, int length)
      Read bytes from the left over buffer into b.
      protected abstract byte leftOverReadSingleByte()
      Read a single byte from the left over buffer.
      protected abstract void leftOverReset()
      Reset the left over buffer.
      boolean markSupported()  
      protected abstract void nextLeftOver​(CloseableIterator<T> iterator)
      Read the next element from the Iterator.
      int read()  
      int read​(byte[] b, int off, int len)  
      • Methods inherited from class java.io.InputStream

        mark, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractCloseableIteratorAsInputStream

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

      • 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 java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

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

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

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

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