Package org.yamcs.tctm
Class GenericPacketInputStream
- java.lang.Object
-
- org.yamcs.tctm.GenericPacketInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,PacketInputStream
public class GenericPacketInputStream extends Object implements PacketInputStream
Generic packet reader that splits the stream into packets based on the length of the packetInspired from Netty's LengthFieldBasedFrameDecoder
The following configuration variables are used
- maxPacketLength - the maximum packet length; if a packet with the length greater than this would be received, the input stream is closed and an exception is raised. The length of the packet considered here is the number of data bytes read from the stream - that is including the length field itself and the bytes to strip at the beginning if set (see below)
- lengthFieldOffset - the offset in the packet where the length is read from
- lengthFieldLength - the size in bytes of the length field
- lengthAdjustment - after reading the length from the configured offset, this variable is added to it to determine the real length
- initialBytesToStrip - after reading the packet, strip this number of bytes from the beginning
All the above configuration parameters have to be set, otherwise a ConfigurationException will be thrown.
-
-
Constructor Summary
Constructors Constructor Description GenericPacketInputStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
init(InputStream inputStream, YConfiguration args)
Called each time an input stream is opened to initialize the objectbyte[]
readPacket()
read the next packet - blocking if necessary until all the data is available.
-
-
-
Method Detail
-
init
public void init(InputStream inputStream, YConfiguration args)
Description copied from interface:PacketInputStream
Called each time an input stream is opened to initialize the object- Specified by:
init
in interfacePacketInputStream
-
readPacket
public byte[] readPacket() throws IOException, PacketTooLongException
Description copied from interface:PacketInputStream
read the next packet - blocking if necessary until all the data is available.- Specified by:
readPacket
in interfacePacketInputStream
- Returns:
- the next packet read from the input stream.
- Throws:
EOFException
- if this input stream reaches the end.IOException
- an I/O error has occurredPacketTooLongException
- if a packet read is longer than a defined limit
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-