public class ConsumingInputStream extends InputStream
InputStream getting its contents from consuming an OutputStream.
The InputStream will be immediately available for reading after construction, regardless
of how much data that will be produced by the OutputStream. This class abstracts the use
of a PipedInputStream and a PipedOutputStream, hiding the
complexities required to orchestrate this multithreaded combination of streams.| Modifier and Type | Class and Description |
|---|---|
static class |
ConsumingInputStream.ProducerFailed |
| Constructor and Description |
|---|
ConsumingInputStream(ExecutorService executorService,
Consumer<? super OutputStream> write)
Create a new
ConsumingInputStream which will provide data once they are written to an
OutputStream passed to the given Consumer. |
ConsumingInputStream(ExecutorService executorService,
Function<OutputStream,S> outputStreamDecorator,
Consumer<? super S> write)
Create a new
ConsumingInputStream which will provide data once they are written to an
OutputStream passed to the given Consumer. |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
public ConsumingInputStream(ExecutorService executorService, Consumer<? super OutputStream> write)
ConsumingInputStream which will provide data once they are written to an
OutputStream passed to the given Consumer.executorService - The executorService to use to start producing data which will be readable by this inputstream.write - The data producing logic. The Consumer will be given the OutputStreamoutputStreamDecorator.public ConsumingInputStream(ExecutorService executorService, Function<OutputStream,S> outputStreamDecorator, Consumer<? super S> write)
ConsumingInputStream which will provide data once they are written to an
OutputStream passed to the given Consumer.executorService - The executorService to use to start producing data which will be readable by this inputstream.outputStreamDecorator - A Function to wrap the outputstream to push data to. This Function must
always wrap the given OutputStream in the OutputStream returned from this Function,
i.e. the resulting OutputStream must be constructed by wrapping the given OutputStream as
a constructor argument. (E.g. ZipOutputStream::new.write - The data producing logic. The Consumer will be given the OutputStreamoutputStreamDecorator.public int read()
throws IOException
read in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic void mark(int readlimit)
mark in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic boolean markSupported()
markSupported in class InputStreamCopyright © 2018 Digipost. All rights reserved.