Package com.unboundid.util
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
ConstructorsConstructorDescriptionAggregateInputStream(boolean ensureBlankLinesBetweenFiles, File... files) Creates a new aggregate input stream that will read data from the specified files.AggregateInputStream(File... files) Creates a new aggregate input stream that will read data from the specified files.AggregateInputStream(InputStream... inputStreams) 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 TypeMethodDescriptionintRetrieves an estimate of the number of bytes that can be read without blocking.voidclose()Closes this input stream.voidmark(int readLimit) Marks the current position in the input stream.booleanIndicates whether this input stream supports the use of themarkandresetmethods.intread()Reads the next byte of data from the current active input stream, switching to the next input stream in the set if appropriate.intread(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.intread(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.voidreset()Attempts to reset the position of this input stream to the mark location.longskip(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, skipNBytes, transferTo
-
Constructor Details
-
AggregateInputStream
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 benull.
-
AggregateInputStream
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 benull.
-
AggregateInputStream
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 benull.- 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 benull.- Throws:
IOException- If a problem is encountered while attempting to create input streams for the provided files.
-
-
Method Details
-
read
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:
readin classInputStream- 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
Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.- Overrides:
readin classInputStream- Parameters:
b- The array into which the data read should be placed, starting with an index of zero. It must not benull.- 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
Reads data from the current active input stream into the provided array, switching to the next input stream in the set if appropriate.- Overrides:
readin classInputStream- Parameters:
b- The array into which the data read should be placed. It must not benull.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
Attempts to skip and discard up to the specified number of bytes from the input stream.- Overrides:
skipin classInputStream- 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
Retrieves an estimate of the number of bytes that can be read without blocking.- Overrides:
availablein classInputStream- 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
Indicates whether this input stream supports the use of themarkandresetmethods. This implementation does not support that capability.- Overrides:
markSupportedin classInputStream- Returns:
falseto indicate that this input stream implementation does not support the use ofmarkandreset.
-
mark
Marks the current position in the input stream. This input stream does not support this functionality, so no action will be taken.- Overrides:
markin classInputStream- Parameters:
readLimit- The maximum number of bytes that the caller may wish to read before being able to reset the stream.
-
reset
Attempts to reset the position of this input stream to the mark location. This implementation does not supportmarkandresetfunctionality, so this method will always throw an exception.- Overrides:
resetin classInputStream- Throws:
IOException- To indicate that reset is not supported.
-
close
Closes this input stream. All associated input streams will be closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- 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.
-