Class JICPPacket


  • public class JICPPacket
    extends Object
    This class is the JICP data packet representation along with methods for reading from and writing to dataXXputStreams.
    Author:
    Ronnie Taib - Motorola, Steffen Rusitschka - Siemens AG
    • Constructor Detail

      • JICPPacket

        public JICPPacket​(byte type,
                          byte info,
                          byte[] data)
        Constructor.
        Parameters:
        type - The type of data included in the packet
        data - The data itself, as a byte array.
      • JICPPacket

        public JICPPacket​(byte type,
                          byte info,
                          String recipientID,
                          byte[] data)
        Constructor used to set the recipientID.
        Parameters:
        type - The type of data included in the packet
        data - The data itself, as a byte array.
      • JICPPacket

        public JICPPacket​(String explanation,
                          Exception e)
        constructs a JICPPacket of type JICPProtocol.ERROR_TYPE and sets the data to the string representation of the exception.
    • Method Detail

      • getType

        public byte getType()
        Returns:
        The type of data included in the packet.
      • getInfo

        public byte getInfo()
        Returns:
        the info field of this packet
      • getSessionID

        public byte getSessionID()
        Returns:
        The sessionID of this packet.
      • setSessionID

        public void setSessionID​(byte id)
        Set the sessionID of this packet and adjust the info field accordingly.
      • getRecipientID

        public String getRecipientID()
        Returns:
        The recipientID of this packet.
      • setRecipientID

        public void setRecipientID​(String id)
        Set the recipientID of this packet and adjust the info field accordingly.
      • setTerminatedInfo

        public void setTerminatedInfo​(boolean set)
        Set the TERMINATED_INFO flag in the info field.
      • getData

        public byte[] getData()
        Returns:
        The actual data included in the packet, as a byte array.
      • writeTo

        public int writeTo​(OutputStream out)
                    throws IOException
        Writes the packet into the provided OutputStream. The packet is serialized in an internal representation, so the data should be retrieved and deserialized with the readFrom() static method below. The output stream is flushed but not opened nor closed by this method.
        Parameters:
        out - The OutputStream to write the data in
        Throws:
        May - send a large bunch of exceptions, mainly in the IO package.
        IOException
      • readFrom

        public static JICPPacket readFrom​(InputStream in)
                                   throws IOException
        This static method reads from a given DataInputStream and returns the JICPPacket that it reads. The input stream is not opened nor closed by this method.
        Parameters:
        in - The InputStream to read from
        Throws:
        May - send a large bunch of exceptions, mainly in the IO package.
        IOException
      • getLength

        public int getLength()