Package no.digipost.io
Class ConsumingInputStream
java.lang.Object
java.io.InputStream
no.digipost.io.ConsumingInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An
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.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionConsumingInputStream(ExecutorService executorService, Consumer<? super OutputStream> write) Create a newConsumingInputStreamwhich will provide data once they are written to anOutputStreampassed to the givenConsumer.ConsumingInputStream(ExecutorService executorService, Function<OutputStream, S> outputStreamDecorator, Consumer<? super S> write) Create a newConsumingInputStreamwhich will provide data once they are written to anOutputStreampassed to the givenConsumer. -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ConsumingInputStream
Create a newConsumingInputStreamwhich will provide data once they are written to anOutputStreampassed to the givenConsumer.- Parameters:
executorService- The executorService to use to start producing data which will be readable by this inputstream.write- The data producing logic. TheConsumerwill be given theOutputStreamresulting from theoutputStreamDecorator.
-
ConsumingInputStream
public ConsumingInputStream(ExecutorService executorService, Function<OutputStream, S> outputStreamDecorator, Consumer<? super S> write) Create a newConsumingInputStreamwhich will provide data once they are written to anOutputStreampassed to the givenConsumer.- Parameters:
executorService- The executorService to use to start producing data which will be readable by this inputstream.outputStreamDecorator- AFunctionto wrap the outputstream to push data to. ThisFunctionmust always wrap the given OutputStream in the OutputStream returned from thisFunction, 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. TheConsumerwill be given theOutputStreamresulting from theoutputStreamDecorator.
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-