Package io.fusionauth.http.io
Class BlockingByteBufferOutputStream
java.lang.Object
java.io.OutputStream
io.fusionauth.http.io.BlockingByteBufferOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
This InputStream uses ByteBuffers read by the Server processor and piped into this class. Those ByteBuffers are then fed to the reader of
the InputStream. The pushing of ByteBuffers blocks based on the configuration and the reading will block if there are no more bytes to
read.
In order to handle chunking and other considerations, this class can be sub-classed to preprocess bytes.
- Author:
- Brian Pontarelli
-
Constructor Summary
ConstructorsConstructorDescriptionBlockingByteBufferOutputStream(Notifier notifier, int bufferSize, int maximumQueueSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()Flushes and then marks the stream closed.voidflush()Flushes the current stream contents if the current ByteBuffer has less than 10% remaining space.booleanbooleanisClosed()booleanisEmpty()Used by the reader side (the selector/processor) so that bytes can be read from the worker thread and written back to the client.voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Constructor Details
-
BlockingByteBufferOutputStream
-
-
Method Details
-
clear
public void clear() -
close
public void close()Flushes and then marks the stream closed. The flush must occur first so that the readers have access to the buffers before they are aware of the stream's closure.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
flush
public void flush()Flushes the current stream contents if the current ByteBuffer has less than 10% remaining space. It flushes by putting the current ByteBuffer into the Queue that the reader thread is reading from. Then it sets the current ByteBuffer to null so that a new one is created. And finally, this notifies the selector to wake up.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
hasReadableBuffer
public boolean hasReadableBuffer() -
isClosed
public boolean isClosed() -
isEmpty
public boolean isEmpty() -
readableBuffer
Used by the reader side (the selector/processor) so that bytes can be read from the worker thread and written back to the client. This method should only be called once per buffer. It pops the buffer off the queue.- Returns:
- A ByteBuffer that is used to read bytes that will be written back to the client or null if there aren't any buffers ready yet.
-
write
public void write(int b) - Specified by:
writein classOutputStream
-
write
public void write(byte[] b, int off, int len) - Overrides:
writein classOutputStream
-