Interface SerialReceiver

All Superinterfaces:
Availability, ByteDestination, ByteReceiver, BytesDestination, BytesReceiver, Closable, Closable.CloseAutomaton, ClosedAccessor, ConnectableComponent, ConnectableComponent.ConnectableAutomaton, ConnectionStatusAccessor, InputStreamAccessor, LinkComponent, LinkComponent.LinkAutomaton, Openable, Openable.OpenAutomaton, OpenedAccessor, Receivable, SegmentDestination, SegmentReceiver, Skippable, TimeoutInputStreamAccessor
All Known Subinterfaces:
Port<PM>, SerialTransceiver
All Known Implementing Classes:
AbstractPort, AbstractPortDecorator, CrossoverLoopbackPort, LoopbackPort

public interface SerialReceiver extends BytesReceiver, SegmentReceiver, LinkComponent.LinkAutomaton, Skippable
A SerialReceiver is used to read data from a serial port or the like.
  • Method Details

    • available

      int available() throws IOException
      Returns the number of bytes which can be read directly e.g. which are already been stored in an internal buffer. May return (0 or) a value less than 0 (-1) when it is not supported. Similar to InputStream.available(): "Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream. A subclass' implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method. The available method for class InputStream always returns 0. This method should be overridden by subclasses."
      Specified by:
      available in interface Availability
      Specified by:
      available in interface Skippable
      Returns:
      The number of available bytes: An estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or 0 when it reaches the end of the input stream. Throws:
      Throws:
      IOException - - if an I/O error occurs.
    • receiveByte

      default byte receiveByte() throws IOException
      Specified by:
      receiveByte in interface ByteDestination
      Specified by:
      receiveByte in interface BytesDestination
      Throws:
      IOException
    • receiveBytes

      default byte[] receiveBytes(int aLength) throws IOException
      Specified by:
      receiveBytes in interface BytesDestination
      Specified by:
      receiveBytes in interface BytesReceiver
      Throws:
      IOException
    • receiveSequenceWithin

      default Sequence receiveSequenceWithin(long aTimeoutMillis, int aLength) throws IOException
      Receives a Sequence with the number of bytes specified. This method blocks till all bytes are read or the timeout has been reached.
      Parameters:
      aTimeoutMillis - The default timeout for read operations not explicitly called with a timeout argument. With a value of -1 timeout handling is disabled (blocking mode) or a technical timeout occurs (implementation depended).
      aLength - The number of bytes to receive.
      Returns:
      A Sequence containing the accordingly received bytes.
      Throws:
      IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
    • receiveSequence

      default Sequence receiveSequence(int aLength) throws IOException
      Receives a Sequence with the number of bytes specified.This method blocks till all bytes are read.
      Parameters:
      aLength - The number of bytes to receive.
      Returns:
      A Sequence containing the accordingly received bytes.
      Throws:
      IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
    • receiveSegmentWithin

      default <SEGMENT extends Segment> void receiveSegmentWithin(long aTimeoutMillis, SEGMENT aSegment) throws IOException
      Receives a Segment (and blocks this thread) till all it's Sequence data has been received and updates the Segment by invoking Segment.fromTransmission(Sequence). This method blocks till all bytes are read or the timeout has been reached.
      Specified by:
      receiveSegmentWithin in interface SegmentReceiver
      Type Parameters:
      SEGMENT - The Segment type describing the Segment subclass of implementing Segment types.
      Parameters:
      aTimeoutMillis - The default timeout for read operations not explicitly called with a timeout argument. With a value of -1 timeout handling is disabled (blocking mode) or a technical timeout occurs (implementation depended).
      aSegment - The Segment to be (re-)initialized with the received data.
      Throws:
      IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
    • receiveSegment

      default <SEGMENT extends Segment> void receiveSegment(SEGMENT aSegment) throws IOException
      Receives a Segment (and blocks this thread) till all it's Sequence data has been received and updates the Segment by invoking Segment.fromTransmission(Sequence). This method blocks till all bytes are read.
      Specified by:
      receiveSegment in interface SegmentDestination
      Type Parameters:
      SEGMENT - The Segment type describing the Segment subclass of implementing Segment types.
      Parameters:
      aSegment - The Segment to be (re-)initialized with the received data.
      Throws:
      IOException - thrown in case of I/O issues (e.g. a timeout) while receiving.
    • open

      void open() throws IOException
      Attention: Implementations of this method should do a Object.notifyAll() in order to terminate any pending asynchronous operations such as SegmentReceiver.onReceiveSegment(Segment) or SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).
      Specified by:
      open in interface Openable
      Throws:
      IOException
    • close

      void close() throws IOException
      Attention: Implementations of this method should do a Object.notifyAll() in order to terminate any pending asynchronous operations such as SegmentReceiver.onReceiveSegment(Segment) or SegmentReceiver.onReceiveSegment(Segment, SegmentConsumer).
      Specified by:
      close in interface Closable
      Throws:
      IOException