Class AbstractPacket.AbstractHeader

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractHeader()  
    • Method Summary

      Modifier and Type Method Description
      protected java.lang.String buildHexString()
      This method builds the value toHexString() will return using the return value of getRawData().
      protected byte[] buildRawData()
      This method builds the value getRawData() will return by concatenating the byte arrays in the list getRawFields() returns.
      protected java.lang.String buildString()
      This method builds the value toString() will return.
      protected int calcHashCode()
      This method builds the value hashCode() will return using the byte array getRawData() returns.
      protected int calcLength()
      This method calculates the value length() will return by adding up the lengths of byte arrays in the list getRawFields() returns.
      boolean equals​(java.lang.Object obj)
      Indicates whether some other object is "equal to" this one using return values of getRawData().
      byte[] getRawData()
      Returns this header's raw data.
      protected abstract java.util.List<byte[]> getRawFields()
      Returns a list of byte arrays which represents this header's fields.
      int hashCode()
      Returns a hash code value for the object.
      int length()
      Returns the header length in bytes.
      java.lang.String toHexString()
      Returns the hex string representation of this object.
      java.lang.String toString()
      Returns a string representation of the object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractHeader

        protected AbstractHeader()
    • Method Detail

      • getRawFields

        protected abstract java.util.List<byte[]> getRawFields()
        Returns a list of byte arrays which represents this header's fields. This method is called by calcLength() and buildRawData().
        Returns:
        a list of byte arrays which represents this header's fields
      • calcLength

        protected int calcLength()
        This method calculates the value length() will return by adding up the lengths of byte arrays in the list getRawFields() returns.
        Returns:
        a calculated length
      • length

        public int length()
        Returns the header length in bytes. This method calls calcLength() and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time.
        Specified by:
        length in interface Packet.Header
        Returns:
        the length of the byte stream of the header represented by this object in bytes
      • buildRawData

        protected byte[] buildRawData()
        This method builds the value getRawData() will return by concatenating the byte arrays in the list getRawFields() returns.
        Returns:
        a raw data built
      • getRawData

        public byte[] getRawData()
        Returns this header's raw data. This method calls buildRawData() and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time. More correctly, this method returns a copy of the cached value, so that the cache can't be changed.
        Specified by:
        getRawData in interface Packet.Header
        Returns:
        the raw data of this packet's header, namely a piece of the byte stream which is actually sent through real network
      • buildHexString

        protected java.lang.String buildHexString()
        This method builds the value toHexString() will return using the return value of getRawData(). Each octet in this return value is separated by a white space. (e.g. 00 01 02 03 aa bb cc)
        Returns:
        a hex string representation of this object
      • toHexString

        public java.lang.String toHexString()
        Returns the hex string representation of this object. This method calls buildHexString() and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time.
        Returns:
        a hex string representation of this object
      • buildString

        protected java.lang.String buildString()
        This method builds the value toString() will return.
        Returns:
        a string representation of this object
      • toString

        public java.lang.String toString()
        Returns a string representation of the object. This method calls buildString() and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time.
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Indicates whether some other object is "equal to" this one using return values of getRawData(). This method should be overridden so that it does more strict comparisons more efficiently.
        Overrides:
        equals in class java.lang.Object
      • calcHashCode

        protected int calcHashCode()
        This method builds the value hashCode() will return using the byte array getRawData() returns. This method may be better to be overridden for performance reason.
        Returns:
        a calculated hash code value for the object
      • hashCode

        public int hashCode()
        Returns a hash code value for the object. This method calls calcHashCode() and caches the return value when it is called for the first time, and then, this method returns the cached value from the second time.
        Overrides:
        hashCode in class java.lang.Object