Class InputStreamIterator

java.lang.Object
no.digipost.io.InputStreamIterator
All Implemented Interfaces:
Iterator<byte[]>

public class InputStreamIterator extends Object implements Iterator<byte[]>
InputStreamIterator is an Iterator reading from an InputStream in chunks where each chunk is returned as the next element in the iterable. When the input stream is fully consumed the iterator has no more elements.
  • Constructor Details

    • InputStreamIterator

      public InputStreamIterator(InputStream inputStream, DataSize chunkSize)
      Parameters:
      inputStream - The input stream to iterate over
      chunkSize - DataSize should not be too big since that defeats the purpose of this iterator.
    • InputStreamIterator

      public InputStreamIterator(InputStream inputStream, int chunkSizeBytes)
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<byte[]>
      Returns:
      true if the iteration has more elements
      Throws:
      UncheckedIOException - if the wrapped InputStream throws an IOException
    • next

      public byte[] next()
      Specified by:
      next in interface Iterator<byte[]>