Class PacketInputStream

java.lang.Object
java.io.InputStream
org.refcodes.serial.PacketInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, org.refcodes.mixin.BlockSizeAccessor, org.refcodes.mixin.PacketSizeAccessor, org.refcodes.numerical.EndianessAccessor, PacketLengthWidthAccessor, PacketMagicBytesAccessor, PacketSegmentPackagerAccessor, SequenceNumberAccessor, SequenceNumberConcatenateModeAccessor, SequenceNumberInitValueAccessor, SequenceNumberWidthAccessor
Direct Known Subclasses:
StopAndWaitPacketInputStream

public class PacketInputStream extends InputStream implements PacketLengthWidthAccessor, org.refcodes.numerical.EndianessAccessor, org.refcodes.mixin.BlockSizeAccessor, SequenceNumberAccessor, SequenceNumberWidthAccessor, SequenceNumberInitValueAccessor, SequenceNumberConcatenateModeAccessor, org.refcodes.mixin.PacketSizeAccessor, PacketSegmentPackagerAccessor, PacketMagicBytesAccessor
The PacketInputStream wraps an InputStream and chunks any data to be written into packets with a sequence number and a block of data. An according PacketInputStream then reverts the packetised data stream while performing sequence number validation. A SegmentPackager can be used to add functionality such as CRC checksum support.
  • Field Details

  • Constructor Details

    • PacketInputStream

      public PacketInputStream(InputStream aInputStream, TransmissionMetrics aTransmissionMetrics)
      Constructs an according PacketInputStream instance wrapping the given InputStream. The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
      Parameters:
      aInputStream - The InputStream to be wrapped.
      aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • PacketInputStream

      public PacketInputStream(InputStream aInputStream, int aBlockSize, int aPacketLengthWidth, byte[] aPacketMagicBytes, int aSequenceNumberInitValue, int aSequenceNumberWidth, org.refcodes.mixin.ConcatenateMode aSequenceNumberConcatenateMode, SegmentPackager aPacketSegmentPackager, org.refcodes.numerical.Endianess aEndianess)
      Constructs an according PacketInputStream instance wrapping the given InputStream.
      Parameters:
      aInputStream - The InputStream to be wrapped.
      aBlockSize - The block size of a data block for each packet.
      aPacketLengthWidth - The width (bytes) for declaring the (max) length of a package.
      aPacketMagicBytes - The magic bytes identifying a packet and distinguishing a packet from a last package.
      aSequenceNumberInitValue - The initial sequence number from where to start counting the blocks.
      aSequenceNumberWidth - The width (in bytes) to be used for sequence number values.
      aSequenceNumberConcatenateMode - The mode of concatenation to use when creating a Sequence from this Transmission and the decorated Transmission.
      aPacketSegmentPackager - An (optional) SegmentPackager used to modify a packet's data e.g. with a CRC checksum.
      aEndianess - The Endianess to use for integer (double) numbers and the like.
  • Method Details