T - the type of message that will be written; see createMessage(byte[], int, int)public abstract class AbstractChannelOutboundInvokingOutputStream<T> extends OutputStream
OutputStream that delegates writing and flushing
operations to a ChannelOutboundInvoker.
Instances of this class are safe for concurrent use by multiple threads.
ChannelOutboundInvoker| Modifier and Type | Field and Description |
|---|---|
protected ChannelOutboundInvoker |
channelOutboundInvoker
The
ChannelOutboundInvoker underlying this AbstractChannelOutboundInvokingOutputStream implementation to
which most operations are adapted. |
protected boolean |
closeChannelOutboundInvoker
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker)
Creates a new
AbstractChannelOutboundInvokingOutputStream
that does not automatically flush and that does not ever
close the supplied
ChannelOutboundInvoker. |
protected |
AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker,
boolean closeChannelOutboundInvoker)
Creates a new
AbstractChannelOutboundInvokingOutputStream
that does not automatically flush. |
protected |
AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker,
int flushThreshold,
boolean closeChannelOutboundInvoker)
Creates a new
AbstractChannelOutboundInvokingOutputStream. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this
AbstractChannelOutboundInvokingOutputStream, optionally
writing and flushing a final message, or simply just flushing first, before possibly closing the
underlying ChannelOutboundInvoker. |
protected T |
createLastMessage()
Returns a new, possibly
null, message that should be
written when close() is invoked. |
protected abstract T |
createMessage(byte[] bytes,
int offset,
int length)
Returns a new message representing a portion (or all) of the
supplied
byte array that will be written by
this AbstractChannelOutboundInvokingOutputStream's
various write methods. |
protected T |
createMessage(int singleByte)
Returns a new message representing the single supplied
byte to be written by this AbstractChannelOutboundInvokingOutputStream's various write methods. |
void |
flush()
Calls the
ChannelOutboundInvoker.flush() method on the
ChannelOutboundInvoker supplied at construction time. |
int |
getFlushThreshold()
Returns the minimum number of bytes that this
AbstractChannelOutboundInvokingOutputStream implementation has
to write before an
automatic flush will take place. |
protected ChannelPromise |
newPromise()
Creates and returns new
ChannelPromises that will be used
in many ChannelOutboundInvoker operations. |
void |
write(byte[] bytes) |
void |
write(byte[] bytes,
int offset,
int length) |
void |
write(int singleByte) |
protected final ChannelOutboundInvoker channelOutboundInvoker
ChannelOutboundInvoker underlying this AbstractChannelOutboundInvokingOutputStream implementation to
which most operations are adapted.protected final boolean closeChannelOutboundInvoker
protected AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker)
AbstractChannelOutboundInvokingOutputStream
that does not automatically flush and that does not ever
close the supplied
ChannelOutboundInvoker.channelOutboundInvoker - the ChannelOutboundInvoker
to which operations are adapted; must not be nullNullPointerException - if channelOutboundInvoker
is nullAbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean),
ChannelOutboundInvokerprotected AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker, boolean closeChannelOutboundInvoker)
AbstractChannelOutboundInvokingOutputStream
that does not automatically flush.channelOutboundInvoker - the ChannelOutboundInvoker
to which operations are adapted; must not be nullcloseChannelOutboundInvoker - whether ChannelOutboundInvoker.close(ChannelPromise) will be called on
the supplied ChannelOutboundInvoker when close() is calledNullPointerException - if channelOutboundInvoker
is nullAbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean),
ChannelOutboundInvoker,
close()protected AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker channelOutboundInvoker, int flushThreshold, boolean closeChannelOutboundInvoker)
AbstractChannelOutboundInvokingOutputStream.channelOutboundInvoker - the ChannelOutboundInvoker
to which operations are adapted; must not be nullflushThreshold - the minimum number of bytes that this
instance has to write
before an automatic flush will take place;
if less than 0 0 will be used instead; if Integer#MAX_VALUE then no automatic flushing will occurcloseChannelOutboundInvoker - whether ChannelOutboundInvoker.close(ChannelPromise) will be called on
the supplied ChannelOutboundInvoker when close() is calledNullPointerException - if channelOutboundInvoker
is nullChannelOutboundInvoker,
getFlushThreshold(),
close()public final int getFlushThreshold()
AbstractChannelOutboundInvokingOutputStream implementation has
to write before an
automatic flush will take place.
This method will always return 0 or a positive int.
If this method returns 0, then a call to flush() will be made at some point after every write(byte[], int, int) invocation.
If this method returns Integer.MAX_VALUE, then no
automatic flushing will occur.
AbstractChannelOutboundInvokingOutputStream implementation has
to write before an
automatic flush will take place; always
0 or a positive intAbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean),
ChannelOutboundInvoker.flush()public final void write(int singleByte) throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] bytes) throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] bytes, int offset, int length) throws IOException
write in class OutputStreamIOExceptionprotected T createMessage(int singleByte) throws IOException
byte to be written by this AbstractChannelOutboundInvokingOutputStream's various write methods.
This method never returns null.
Overrides of this method must not return null.
Note: The default implementation of this
method is inefficient: it creates a new byte[] holding
the sole byte represented by the singleByte
parameter value and calls createMessage(byte[], int,
int) and returns its result. Subclasses are encouraged, but not
required, to override this method to be more efficient.
Overrides of this method should be stateless.
singleByte - an int whose low-order bits hold a
byte to be writtennull message to writeIOException - if an error occurscreateMessage(byte[], int, int),
ChannelOutboundInvoker.write(Object, ChannelPromise)protected abstract T createMessage(byte[] bytes, int offset, int length) throws IOException
byte array that will be written by
this AbstractChannelOutboundInvokingOutputStream's
various write methods.
Implementations of this method must not return null.
Implementations of this method should be stateless.
bytes - a byte array originating from,
e.g., a write(byte[], int, int) method
invocation; will never be nulloffset - the (validated) offset within the supplied byte array from which to start reading; will always be 0
or a positive int less than lengthlength - the (validated) length of the portion to read; will
always be 0 or a positive int less than or equal
to the length of the supplied byte arraynull message to writeNullPointerException - if bytes is nullIndexOutOfBoundsException - if offset is
negative, or length is negative, or offset +
length is greater than the length of bytesIOException - if an error occurs during the actual
creation of the messagewrite(byte[], int, int),
OutputStream.write(byte[], int, int),
ChannelOutboundInvoker.write(Object, ChannelPromise)protected T createLastMessage() throws IOException
null, message that should be
written when close() is invoked.
This method and its overrides may return null to
indicate that no such write is required.
The default implementation of this method returns null.
Overrides of this method should be stateless.
close() is
called, or null if no final message needs to be writtenIOException - if an error occursclose()protected ChannelPromise newPromise()
ChannelPromises that will be used
in many ChannelOutboundInvoker operations.
This method never returns null.
Overrides of this method must not return null.
The default implementation of this method returns the return
value of invoking ChannelOutboundInvoker.newPromise().
null ChannelPromise that will
be supplied to many ChannelOutboundInvoker operationsChannelPromise,
ChannelOutboundInvoker.newPromise(),
ChannelOutboundInvoker.voidPromise()public final void flush()
ChannelOutboundInvoker.flush() method on the
ChannelOutboundInvoker supplied at construction time.flush in interface Flushableflush in class OutputStreamChannelOutboundInvoker.flush(),
getFlushThreshold(),
AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean)public final void close() throws IOException
AbstractChannelOutboundInvokingOutputStream, optionally
writing and flushing a final message, or simply just flushing first, before possibly closing the
underlying ChannelOutboundInvoker.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if the createLastMessage() method
throws an IOExceptioncreateLastMessage(),
ChannelOutboundInvoker.close(ChannelPromise),
AbstractChannelOutboundInvokingOutputStream(ChannelOutboundInvoker,
int, boolean)Copyright © 2019–2020, microBean™. All rights reserved.