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
, Availability
, ByteDestination
, ByteReceiver
, BytesDestination
, BytesReceiver
, Receivable
, Skippable
, TimeoutInputStreamAccessor
, org.refcodes.mixin.InputStreamAccessor
public class BytesReceiverDecorator extends AbstractBytesReceiver implements BytesReceiver
BytesReceiverDecorator
decorates a BytesDestination
with
the additional methods of a BytesReceiver
making it easy to use a
BytesDestination
wherever a BytesReceiver
is expected. This
is a very plain implementation: available()
always returns true if
AbstractBytesReceiver.isOpened()
is true and as long as none of the
receiveByte()
, receiveAllBytes()
or
receiveBytes(int)
methods threw an IOException
(
InterruptedException
). This implementation actually behaves as if
close()
has been called after verifying available()
and
before any of the read methods have been called.AbstractBytesReceiver.ConnectableAutomaton
BytesReceiver.ReceiverInputStream
org.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.ClosedProperty
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamProperty
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B extends TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<?>>, TimeoutInputStreamAccessor.TimeoutInputStreamMutator, TimeoutInputStreamAccessor.TimeoutInputStreamProperty
_datagramQueue, DATAGRAM_QUEUE_SIZE
_automaton
Constructor | Description |
---|---|
BytesReceiverDecorator(BytesDestination aByteProvider) |
Instantiates a new byte receiver decorator.
|
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
Determines the number of available datagram from a
DatagramTransmitter . |
void |
close() |
|
byte[] |
receiveAllBytes() |
Reads (receives) the all currently available data.
|
byte |
receiveByte() |
Reads (receives) the next byte, in case none byte is available, then this
method blocks until one is available.
|
byte[] |
receiveBytes(int aMaxLength) |
Similar to
BytesDestination.receiveAllBytes() though at maximum the amount of
data as of the provided length returned. |
pushDatagram, pushDatagrams, pushDatagrams
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
hasAvailable
receiveBytes
getInputStream, getInputStream, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skip
closeIn, closeQuietly, closeUnchecked
getConnectionStatus, isOpened
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableTillSilenceFor, skipAvailableWithin, skipAvailableWithin
public BytesReceiverDecorator(BytesDestination aByteProvider)
aByteProvider
- the byte providerpublic byte receiveByte() throws IOException
receiveByte
in interface ByteDestination
receiveByte
in interface BytesDestination
receiveByte
in class AbstractBytesReceiver
IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public int available() throws IOException
DatagramTransmitter
. Use the DatagramDestination
extenison's DatagramDestination.receive()
method for retrieving
available datagrams.available
in interface Availability
available
in interface Skippable
available
in class AbstractBytesReceiver
IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public byte[] receiveAllBytes() throws IOException
receiveAllBytes
in interface BytesDestination
receiveAllBytes
in interface BytesReceiver
receiveAllBytes
in class AbstractBytesReceiver
DatagramsTransmitter
or DatagramReceiver
counterpart.IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public byte[] receiveBytes(int aMaxLength) throws IOException
BytesDestination.receiveAllBytes()
though at maximum the amount of
data as of the provided length returned.receiveBytes
in interface BytesDestination
receiveBytes
in interface BytesReceiver
receiveBytes
in class AbstractBytesReceiver
aMaxLength
- 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 BytesDestination.receiveAllBytes()
.DatagramsTransmitter
or DatagramReceiver
counterpart.IOException
- Thrown in case opening or accessing an open line
(connection, junction, link) caused problems.public void close() throws IOException
close
in interface org.refcodes.component.Closable
close
in class AbstractBytesReceiver
IOException
Copyright © 2021. All rights reserved.