org.refcodes.component.Closable, org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.ClosedAccessor, org.refcodes.component.ConnectableComponent, org.refcodes.component.ConnectableComponent.ConnectableAutomaton, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.OpenedAccessor, ByteBlockProvider, ByteBlockReceiver, ByteDatagramProvider, ByteDatagramReceiver, ByteProvider, ByteReceiver, Receivable, org.refcodes.mixin.Releaseablepublic class ByteReceiverDecorator extends AbstractByteReceiver implements ByteReceiver
ByteReceiverDecorator decorates a ByteProvider with the
additional methods of a ByteReceiver making it easy to use a
ByteProvider wherever a ByteReceiver is expected.
This is a very plain implementation: hasDatagram() always returns
true if AbstractByteReceiver.isOpened() is true and as long as none of the
readDatagram(), readDatagrams() or
readDatagrams(int) methods threw an OpenException (
InterruptedException).
This implementation actually behaves as if close() has been called
after verifying hasDatagram() and before any of the read methods
have been called.AbstractByteReceiver.ConnectableAutomatonorg.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedPropertyorg.refcodes.component.ConnectableComponent.ConnectableAutomaton_datagramQueue, DATAGRAM_QUEUE_SIZE_automaton| Constructor | Description |
|---|---|
ByteReceiverDecorator(ByteProvider aByteProvider) |
Instantiates a new byte receiver decorator.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
boolean |
hasDatagram() |
Determines whether a datagram is available from a
DatagramSender. |
byte |
readDatagram() |
Reads (receives) the next byte passed from a
DatagramSender
counterpart. |
byte[] |
readDatagrams() |
Caution: Reads till an
OpenException (or an
InterruptedException in case of blocking till more data is
available) occurs. |
byte[] |
readDatagrams(int aBlockSize) |
Similar to
ByteBlockProvider.readDatagrams() though at maximum the amount of data
as provided by the block-size is returned. |
pushDatagram, pushDatagrams, pushDatagramsgetConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, releaseAll, setConnectionStatuscloseIn, closeQuietly, closeUncheckedgetConnectionStatus, isConnectionOpenedpublic ByteReceiverDecorator(ByteProvider aByteProvider)
aByteProvider - the byte providerpublic byte readDatagram()
throws org.refcodes.component.OpenException,
InterruptedException
DatagramSender
counterpart. In case none byte is available, then this method blocks
until one is available.
To prevent blocking, use the ByteDatagramReceiver extension's
Receivable.hasDatagram() method to test beforehand
whether a byte is available (in a multi-threaded usage scenario,
Receivable.hasDatagram() is not a reliable indicator
whether this method will block or not).
When a Thread is waiting for a byte to be read and
Thread.interrupt() is being called, then the operation is aborted
and an InterruptedException is thrown.readDatagram in interface ByteDatagramProviderreadDatagram in class AbstractByteReceiverByteDatagramSender
counterpart.org.refcodes.component.OpenException - Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException - Thrown when a Thread is waiting,
sleeping, or otherwise occupied, and the Thread is
interrupted, either before or during the activity.public boolean hasDatagram()
throws org.refcodes.component.OpenException
DatagramSender.
Use the DatagramProvider extenison's
DatagramProvider.readDatagram() method for retrieving the
available datagram.hasDatagram in interface ReceivablehasDatagram in class AbstractByteReceiverorg.refcodes.component.OpenException - Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public byte[] readDatagrams()
throws org.refcodes.component.OpenException,
InterruptedException
OpenException (or an
InterruptedException in case of blocking till more data is
available) occurs.
Reads (receives) the next byte block passed from a BlockSender or
DatagramSender counterpart. In case none byte block is available,
then this method blocks until one is available.
When a Thread is waiting for a byte to be read and
Thread.interrupt() is being called, then the operation is aborted
and an InterruptedException is thrown.readDatagrams in interface ByteBlockProviderreadDatagrams in interface ByteProviderreadDatagrams in interface ByteReceiverreadDatagrams in class AbstractByteReceiverBlockSender or
DatagramReceiver counterpart.org.refcodes.component.OpenException - Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException - Thrown when a Thread is waiting,
sleeping, or otherwise occupied, and the Thread is
interrupted, either before or during the activity.public byte[] readDatagrams(int aBlockSize)
throws org.refcodes.component.OpenException,
InterruptedException
ByteBlockProvider.readDatagrams() though at maximum the amount of data
as provided by the block-size is returned.readDatagrams in interface ByteBlockProviderreadDatagrams in interface ByteProviderreadDatagrams in interface ByteReceiverreadDatagrams in class AbstractByteReceiveraBlockSize - The block-size which is not to exceeded by the returned
data. A value of -1 specifies to retrieve all available datagrams
(same behavior as method ByteBlockProvider.readDatagrams().BlockSender or
DatagramReceiver counterpart.org.refcodes.component.OpenException - Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.InterruptedException - Thrown when a Thread is waiting,
sleeping, or otherwise occupied, and the Thread is
interrupted, either before or during the activity.public void close()
throws org.refcodes.component.CloseException
close in interface org.refcodes.component.Closableclose in class AbstractByteReceiverorg.refcodes.component.CloseExceptionCopyright © 2018. All rights reserved.