it.unimi.dsi.fastutil.io
Class MeasurableInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by it.unimi.dsi.fastutil.io.MeasurableInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
FastBufferedInputStream, FastByteArrayInputStream

public abstract class MeasurableInputStream
extends InputStream

An InputStream that provides eager access to its length, and keeps track of the current position (e.g., the number of bytes read so far).

This class adds two methods, both specified as optional. This apparently bizarre behaviour is necessary because of wrapper classes which use reflection to support those methods (see, e.g., FastBufferedInputStream).

Since:
5.0.4

Constructor Summary
MeasurableInputStream()
           
 
Method Summary
abstract  long length()
          Returns the overall length of this input stream (optional operation).
abstract  long position()
          Returns the current position in this input stream (optional operation).
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MeasurableInputStream

public MeasurableInputStream()
Method Detail

length

public abstract long length()
                     throws IOException
Returns the overall length of this input stream (optional operation). In most cases, this will require the input stream to perform some extra action, possibly changing the state of the input stream itself (typically, reading all the bytes up to the end). Implementing classes should always document what state will the input stream be in after calling this method, and which kind of exception could be thrown.

Throws:
IOException

position

public abstract long position()
                       throws IOException
Returns the current position in this input stream (optional operation).

Usually, the position is just the number of bytes read since the stream was opened, but in the case of a RepositionableStream it represent the current position.

Throws:
IOException