Class BoundedCountingInputStream

java.lang.Object
java.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.law.warc.io.BoundedCountingInputStream
All Implemented Interfaces:
MeasurableStream, Closeable, AutoCloseable

public class BoundedCountingInputStream
extends MeasurableInputStream
A class that decorates an InputStream to obtain a MeasurableInputStream.

This class serves two purpose: wrap an input stream so that no more than a certain number of bytes may be read from it (and that the total number of bytes read so far is available). Moreover, if a CRC32 is given, the content is also checked using it.

Observe that the underlying stream can be null if the empty constructor is called but setInput(InputStream, long, CRC32) is not called; this will lead to NullPointerException in almost every call.

  • Field Details

    • crc

      public CRC32 crc
      A class to compute the crc of read bytes.
  • Constructor Details

    • BoundedCountingInputStream

      public BoundedCountingInputStream()
      Builds the bounded stream.

      Before actually using an object constructed with this, setInput(InputStream, long, CRC32) must be called.

    • BoundedCountingInputStream

      public BoundedCountingInputStream​(InputStream is, long bound, CRC32 crc) throws IOException
      Builds the bounded stream.
      Parameters:
      is - the stream.
      bound - the maximum number of bytes that can be read.
      crc - if not null, it will be used to compute the crc of read bytes.
      Throws:
      IOException
    • BoundedCountingInputStream

      public BoundedCountingInputStream​(InputStream is, long bound) throws IOException
      Builds the bounded stream.
      Parameters:
      is - the stream.
      bound - the maximum number of bytes that can be read.
      Throws:
      IOException
  • Method Details