Class InputStreamContentProvider.InputStreamContentProviderIterator

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.util.Iterator<java.nio.ByteBuffer>
    Enclosing class:
    InputStreamContentProvider

    private class InputStreamContentProvider.InputStreamContentProviderIterator
    extends java.lang.Object
    implements java.util.Iterator<java.nio.ByteBuffer>, java.io.Closeable
    Iterating over an InputStream is tricky, because hasNext() must return false if the stream reads -1. However, we don't know what to return until we read the stream, which means that stream reading must be performed by hasNext(), which introduces a side-effect on what is supposed to be a simple query method (with respect to the Query Command Separation Principle).

    Alternatively, we could return true from hasNext() even if we don't know that we will read -1, but then when next() reads -1 it must return an empty buffer. However this is problematic, since GETs with no content indication would become GET with chunked content, and not understood by servers.

    Therefore we need to make sure that hasNext() does not perform any side effect (so that it can be called multiple times) until next() is called.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer buffer  
      private java.lang.Throwable failure  
      private java.lang.Boolean hasNext  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean hasNext()  
      java.nio.ByteBuffer next()  
      void remove()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • failure

        private java.lang.Throwable failure
      • buffer

        private java.nio.ByteBuffer buffer
      • hasNext

        private java.lang.Boolean hasNext
    • Constructor Detail

      • InputStreamContentProviderIterator

        private InputStreamContentProviderIterator()
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<java.nio.ByteBuffer>
      • next

        public java.nio.ByteBuffer next()
        Specified by:
        next in interface java.util.Iterator<java.nio.ByteBuffer>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<java.nio.ByteBuffer>
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable