Class AggregateInputStream

java.lang.Object
java.io.InputStream
com.unboundid.util.AggregateInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

This class provides an input stream implementation that can aggregate multiple input streams. When reading data from this input stream, it will read from the first input stream until the end of it is reached, at point it will close it and start reading from the next one, and so on until all input streams have been exhausted. Closing the aggregate input stream will cause all remaining input streams to be closed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AggregateInputStream(boolean ensureBlankLinesBetweenFiles, File... files)
    Creates a new aggregate input stream that will read data from the specified files.
    Creates a new aggregate input stream that will read data from the specified files.
    Creates a new aggregate input stream that will use the provided set of input streams.
    AggregateInputStream(Collection<? extends InputStream> inputStreams)
    Creates a new aggregate input stream that will use the provided set of input streams.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Retrieves an estimate of the number of bytes that can be read without blocking.
    void
    Closes this input stream.
    void
    mark(int readLimit)
    Marks the current position in the input stream.
    boolean
    Indicates whether this input stream supports the use of the mark and reset methods.
    int
    Reads the next byte of data from the current active input stream, switching to the next input stream in the set if appropriate.
    int
    read(byte[] b)
    Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.
    int
    read(byte[] b, int off, int len)
    Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.
    void
    Attempts to reset the position of this input stream to the mark location.
    long
    skip(long n)
    Attempts to skip and discard up to the specified number of bytes from the input stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AggregateInputStream

      public AggregateInputStream(@NotNull InputStream... inputStreams)
      Creates a new aggregate input stream that will use the provided set of input streams.
      Parameters:
      inputStreams - The input streams to be used by this aggregate input stream. It must not be null.
    • AggregateInputStream

      public AggregateInputStream(@NotNull Collection<? extends InputStream> inputStreams)
      Creates a new aggregate input stream that will use the provided set of input streams.
      Parameters:
      inputStreams - The input streams to be used by this aggregate input stream. It must not be null.
    • AggregateInputStream

      public AggregateInputStream(@NotNull File... files) throws IOException
      Creates a new aggregate input stream that will read data from the specified files.
      Parameters:
      files - The set of files to be read by this aggregate input stream. It must not be null.
      Throws:
      IOException - If a problem is encountered while attempting to create input streams for the provided files.
    • AggregateInputStream

      public AggregateInputStream(boolean ensureBlankLinesBetweenFiles, @NotNull File... files) throws IOException
      Creates a new aggregate input stream that will read data from the specified files.
      Parameters:
      ensureBlankLinesBetweenFiles - Indicates whether to ensure that there is at least one completely blank line between files. This may be useful when blank lines are used as delimiters (for example, when reading LDIF data), there is a chance that the files may not end with blank lines, and the inclusion of extra blank lines between files will not cause any harm.
      files - The set of files to be read by this aggregate input stream. It must not be null.
      Throws:
      IOException - If a problem is encountered while attempting to create input streams for the provided files.
  • Method Details

    • read

      public int read() throws IOException
      Reads the next byte of data from the current active input stream, switching to the next input stream in the set if appropriate.
      Specified by:
      read in class InputStream
      Returns:
      The next byte of data that was read, or -1 if all streams have been exhausted.
      Throws:
      IOException - If a problem is encountered while attempting to read data from an input stream.
    • read

      public int read(@NotNull byte[] b) throws IOException
      Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.
      Overrides:
      read in class InputStream
      Parameters:
      b - The array into which the data read should be placed, starting with an index of zero. It must not be null.
      Returns:
      The number of bytes read into the array, or -1 if all streams have been exhausted.
      Throws:
      IOException - If a problem is encountered while attempting to read data from an input stream.
    • read

      public int read(@NotNull byte[] b, int off, int len) throws IOException
      Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.
      Overrides:
      read in class InputStream
      Parameters:
      b - The array into which the data read should be placed. It must not be null.
      off - The position in the array at which to start writing data.
      len - The maximum number of bytes that may be read.
      Returns:
      The number of bytes read into the array, or -1 if all streams have been exhausted.
      Throws:
      IOException - If a problem is encountered while attempting to read data from an input stream.
    • skip

      public long skip(long n) throws IOException
      Attempts to skip and discard up to the specified number of bytes from the input stream.
      Overrides:
      skip in class InputStream
      Parameters:
      n - The number of bytes to attempt to skip.
      Returns:
      The number of bytes actually skipped.
      Throws:
      IOException - If a problem is encountered while attempting to skip data from the input stream.
    • available

      public int available() throws IOException
      Retrieves an estimate of the number of bytes that can be read without blocking.
      Overrides:
      available in class InputStream
      Returns:
      An estimate of the number of bytes that can be read without blocking.
      Throws:
      IOException - If a problem is encountered while attempting to make the determination.
    • markSupported

      public boolean markSupported()
      Indicates whether this input stream supports the use of the mark and reset methods. This implementation does not support that capability.
      Overrides:
      markSupported in class InputStream
      Returns:
      false to indicate that this input stream implementation does not support the use of mark and reset.
    • mark

      public void mark(int readLimit)
      Marks the current position in the input stream. This input stream does not support this functionality, so no action will be taken.
      Overrides:
      mark in class InputStream
      Parameters:
      readLimit - The maximum number of bytes that the caller may wish to read before being able to reset the stream.
    • reset

      public void reset() throws IOException
      Attempts to reset the position of this input stream to the mark location. This implementation does not support mark and reset functionality, so this method will always throw an exception.
      Overrides:
      reset in class InputStream
      Throws:
      IOException - To indicate that reset is not supported.
    • close

      public void close() throws IOException
      Closes this input stream. All associated input streams will be closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - If an exception was encountered while attempting to close any of the associated streams. Note that even if an exception is encountered, an attempt will be made to close all streams.