- java.lang.Object
-
- org.refcodes.io.AbstractBytesDestination
-
- org.refcodes.io.AbstractBytesReceiver
-
- org.refcodes.io.BytesReceiverDecorator
-
- All Implemented Interfaces:
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
,org.refcodes.mixin.Loggable
public class BytesReceiverDecorator extends AbstractBytesReceiver implements BytesReceiver
TheBytesReceiverDecorator
decorates aBytesDestination
with the additional methods of aBytesReceiver
making it easy to use aBytesDestination
wherever aBytesReceiver
is expected. This is a very plain implementation:available()
always returns true ifAbstractBytesReceiver.isOpened()
is true and as long as none of thereceiveByte()
,receiveAllBytes()
orreceiveBytes(int)
methods threw anIOException
(InterruptedException
). This implementation actually behaves as ifclose()
has been called after verifyingavailable()
and before any of the read methods have been called.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.refcodes.io.AbstractBytesReceiver
AbstractBytesReceiver.ConnectableAutomaton
-
Nested classes/interfaces inherited from interface org.refcodes.io.BytesReceiver
BytesReceiver.ReceiverInputStream
-
Nested classes/interfaces inherited from interface org.refcodes.component.Closable
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ClosedAccessor
org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectableComponent
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.InputStreamAccessor
org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<B extends org.refcodes.mixin.InputStreamAccessor.InputStreamBuilder<?>>, org.refcodes.mixin.InputStreamAccessor.InputStreamMutator, org.refcodes.mixin.InputStreamAccessor.InputStreamProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.io.TimeoutInputStreamAccessor
TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<B extends TimeoutInputStreamAccessor.TimeoutInputStreamBuilder<?>>, TimeoutInputStreamAccessor.TimeoutInputStreamMutator, TimeoutInputStreamAccessor.TimeoutInputStreamProperty
-
-
Field Summary
-
Fields inherited from class org.refcodes.io.AbstractBytesReceiver
_automaton
-
Fields inherited from class org.refcodes.io.AbstractBytesDestination
_datagramQueue, DATAGRAM_QUEUE_SIZE
-
-
Constructor Summary
Constructors Constructor Description BytesReceiverDecorator(BytesDestination aByteProvider)
Instantiates a new byte receiver decorator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Determines the number of available datagram from aDatagramTransmitter
.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 toBytesDestination.receiveAllBytes()
though at maximum the amount of data as of the provided length returned.-
Methods inherited from class org.refcodes.io.AbstractBytesReceiver
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
-
Methods inherited from class org.refcodes.io.AbstractBytesDestination
pushDatagram, pushDatagrams, pushDatagrams
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.io.Availability
hasAvailable
-
Methods inherited from interface org.refcodes.io.BytesDestination
receiveBytes
-
Methods inherited from interface org.refcodes.io.BytesReceiver
getInputStream, getInputStream, receiveBytesWithin, receiveBytesWithin, receiveByteWithin, skip
-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isOpened
-
Methods inherited from interface org.refcodes.mixin.Loggable
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
-
Methods inherited from interface org.refcodes.io.Skippable
skipAvailable, skipAvailableExcept, skipAvailableTill, skipAvailableTillSilenceFor, skipAvailableTillSilenceFor, skipAvailableWithin, skipAvailableWithin
-
-
-
-
Constructor Detail
-
BytesReceiverDecorator
public BytesReceiverDecorator(BytesDestination aByteProvider)
Instantiates a new byte receiver decorator.- Parameters:
aByteProvider
- the byte provider
-
-
Method Detail
-
receiveByte
public byte receiveByte() throws IOException
Reads (receives) the next byte, in case none byte is available, then this method blocks until one is available.- Specified by:
receiveByte
in interfaceByteDestination
- Specified by:
receiveByte
in interfaceBytesDestination
- Overrides:
receiveByte
in classAbstractBytesReceiver
- Returns:
- The next byte available .
- Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
available
public int available() throws IOException
Determines the number of available datagram from aDatagramTransmitter
. Use theDatagramDestination
extenison'sDatagramDestination.receive()
method for retrieving available datagrams.- Specified by:
available
in interfaceAvailability
- Specified by:
available
in interfaceSkippable
- Overrides:
available
in classAbstractBytesReceiver
- Returns:
- The number of datagrams ready to be retrieved .
- Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
receiveAllBytes
public byte[] receiveAllBytes() throws IOException
Reads (receives) the all currently available data.- Specified by:
receiveAllBytes
in interfaceBytesDestination
- Specified by:
receiveAllBytes
in interfaceBytesReceiver
- Overrides:
receiveAllBytes
in classAbstractBytesReceiver
- Returns:
- The according data.
- Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
receiveBytes
public byte[] receiveBytes(int aMaxLength) throws IOException
Similar toBytesDestination.receiveAllBytes()
though at maximum the amount of data as of the provided length returned.- Specified by:
receiveBytes
in interfaceBytesDestination
- Specified by:
receiveBytes
in interfaceBytesReceiver
- Overrides:
receiveBytes
in classAbstractBytesReceiver
- Parameters:
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 methodBytesDestination.receiveAllBytes()
.- Returns:
- The according data.
- Throws:
IOException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.EOFException
- Signals that an end of file or end of stream has been reached unexpectedly during input.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceorg.refcodes.component.Closable
- Overrides:
close
in classAbstractBytesReceiver
- Throws:
IOException
-
-