Class AggregateInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @ThreadSafety(level=NOT_THREADSAFE)
    public final class AggregateInputStream
    extends java.io.InputStream
    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, java.io.File... files)
      Creates a new aggregate input stream that will read data from the specified files.
      AggregateInputStream​(java.io.File... files)
      Creates a new aggregate input stream that will read data from the specified files.
      AggregateInputStream​(java.io.InputStream... inputStreams)
      Creates a new aggregate input stream that will use the provided set of input streams.
      AggregateInputStream​(java.util.Collection<? extends java.io.InputStream> inputStreams)
      Creates a new aggregate input stream that will use the provided set of input streams.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Retrieves an estimate of the number of bytes that can be read without blocking.
      void close()
      Closes this input stream.
      void mark​(int readLimit)
      Marks the current position in the input stream.
      boolean markSupported()
      Indicates whether this input stream supports the use of the mark and reset methods.
      int read()
      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 reset()
      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.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

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

      • AggregateInputStream

        public AggregateInputStream​(java.io.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​(java.util.Collection<? extends java.io.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​(java.io.File... files)
                             throws java.io.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:
        java.io.IOException - If a problem is encountered while attempting to create input streams for the provided files.
      • AggregateInputStream

        public AggregateInputStream​(boolean ensureBlankLinesBetweenFiles,
                                    java.io.File... files)
                             throws java.io.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:
        java.io.IOException - If a problem is encountered while attempting to create input streams for the provided files.
    • Method Detail

      • read

        public int read()
                 throws java.io.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 java.io.InputStream
        Returns:
        The next byte of data that was read, or -1 if all streams have been exhausted.
        Throws:
        java.io.IOException - If a problem is encountered while attempting to read data from an input stream.
      • read

        public int read​(byte[] b)
                 throws java.io.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 java.io.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:
        java.io.IOException - If a problem is encountered while attempting to read data from an input stream.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.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 java.io.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:
        java.io.IOException - If a problem is encountered while attempting to read data from an input stream.
      • skip

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

        public int available()
                      throws java.io.IOException
        Retrieves an estimate of the number of bytes that can be read without blocking.
        Overrides:
        available in class java.io.InputStream
        Returns:
        An estimate of the number of bytes that can be read without blocking.
        Throws:
        java.io.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 java.io.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 java.io.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 java.io.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 java.io.InputStream
        Throws:
        java.io.IOException - To indicate that reset is not supported.
      • close

        public void close()
                   throws java.io.IOException
        Closes this input stream. All associated input streams will be closed.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.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.