Class AbstractBytesReceiver

java.lang.Object
org.refcodes.io.AbstractBytesDestination
org.refcodes.io.AbstractBytesReceiver
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
Direct Known Subclasses:
AbstractPrefetchInputStreamByteReceiver, ByteArrayReceiver, BytesReceiverDecorator, LoopbackBytesReceiver, LoopbackBytesTransceiver

public abstract class AbstractBytesReceiver extends AbstractBytesDestination implements BytesReceiver
The AbstractBytesReceiver is a base abstract implementation of the BytesReceiver interface providing common functionality for concrete real live implementations.
  • Field Details

  • Constructor Details

    • AbstractBytesReceiver

      public AbstractBytesReceiver()
      Constructs a AbstractBytesReceiver with a default sized blocking queue enabling a maximum of AbstractBytesDestination.DATAGRAM_QUEUE_SIZE datagrams. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue. In case the queue is filled up, adding elements via AbstractBytesDestination.pushDatagram(byte) to the queue is blocked until elements are taken from the queue via receiveByte().
    • AbstractBytesReceiver

      public AbstractBytesReceiver(int aCapacity)
      Constructs a AbstractBytesReceiver with a custom sized blocking queue enabling a maximum of datagrams as specified by the capacity parameter. ------------------------------------------------------------------------- Make sure your code fetches the datagrams quick enough to prevent filling up of the queue. In case the queue is filled up, adding elements via AbstractBytesDestination.pushDatagram(byte) to the queue is blocked until elements are taken from the queue via receiveByte().
      Parameters:
      aCapacity - The capacity of the queue holding the received datagrams.
  • Method Details

    • receiveByte

      public byte receiveByte() throws IOException, EOFException
      Reads (receives) the next byte, in case none byte is available, then this method blocks until one is available.
      Specified by:
      receiveByte in interface ByteDestination
      Specified by:
      receiveByte in interface BytesDestination
      Overrides:
      receiveByte in class AbstractBytesDestination
      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.
    • receiveAllBytes

      public byte[] receiveAllBytes() throws IOException, EOFException
      Reads (receives) the all currently available data.
      Specified by:
      receiveAllBytes in interface BytesDestination
      Specified by:
      receiveAllBytes in interface BytesReceiver
      Overrides:
      receiveAllBytes in class AbstractBytesDestination
      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, EOFException
      Similar to BytesDestination.receiveAllBytes() though at maximum the amount of data as of the provided length returned.
      Specified by:
      receiveBytes in interface BytesDestination
      Specified by:
      receiveBytes in interface BytesReceiver
      Overrides:
      receiveBytes in class AbstractBytesDestination
      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 method BytesDestination.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.
    • available

      public int available() throws IOException
      Determines the number of available datagram from a DatagramTransmitter. Use the DatagramDestination extenison's DatagramDestination.receive() method for retrieving available datagrams.
      Specified by:
      available in interface Availability
      Specified by:
      available in interface Skippable
      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.
    • close

      public void close() throws IOException
      Specified by:
      close in interface org.refcodes.component.Closable
      Throws:
      IOException
    • isOpened

      public boolean isOpened()
      Specified by:
      isOpened in interface org.refcodes.component.ConnectionStatusAccessor
      Specified by:
      isOpened in interface org.refcodes.component.OpenedAccessor
    • isClosable

      public boolean isClosable()
      Specified by:
      isClosable in interface org.refcodes.component.Closable.CloseAutomaton
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface org.refcodes.component.ClosedAccessor
    • getConnectionStatus

      public org.refcodes.component.ConnectionStatus getConnectionStatus()
      Specified by:
      getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessor
    • open

      protected void open() throws IOException
      Open.
      Throws:
      IOException - the open exception
    • setConnectionStatus

      protected void setConnectionStatus(org.refcodes.component.ConnectionStatus aConnectionStatus)
      Sets the connection status.
      Parameters:
      aConnectionStatus - the new connection status
    • isOpenable

      protected boolean isOpenable()
      Checks if is openable.
      Returns:
      true, if is openable