Class MultipleInputStream

java.lang.Object
java.io.InputStream
it.unimi.dsi.io.MultipleInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class MultipleInputStream extends InputStream
A multiple input stream.

Instances of this class encapsulate a sequence of input streams. When one of the streams is exhausted, the multiple stream behaves as if on an end of file. However, after calling reset() the stream is again readable, and positioned at the start of the following stream.

  • Method Details

    • getStream

      public static InputStream getStream(InputStream[] inputStream, int offset, int length)
      Returns an input stream encapsulating a nonempty fragment of an array of input streams.
      Parameters:
      inputStream - an array of input streams, that will be encapsulated.
      offset - the first input stream that will be encapsulated.
      length - the number of input streams to be encapsulated.
      Returns:
      an input stream encapsulating the argument streams (the only argument, if length is 1).
    • getStream

      public static InputStream getStream(InputStream[] inputStream)
      Returns an input stream encapsulating a nonempty array of input streams.

      Note that if inputStream.length is 1 this method will return the only stream that should be encapsulated.

      Parameters:
      inputStream - an array of input streams, that will be encapsulated.
      Returns:
      an input stream encapsulating the argument streams (the only argument, if the length is 1).
    • available

      public int available() throws IOException
      Overrides:
      available in class InputStream
      Throws:
      IOException
    • close

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

      public boolean markSupported()
      Overrides:
      markSupported in class InputStream
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class InputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class InputStream
      Throws:
      IOException