Class PcapPacket

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<Packet>, Packet

    public final class PcapPacket
    extends AbstractPacket
    Pseudo packet to hold a timestamp, an original length, and a raw data of a captured packet. This class doesn't dissect the raw data until certain methods (refer to each method's javadoc) are called. Instances of this class are not immutable.
    Since:
    pcap4j 2.0.0
    Author:
    Kaito Yamada
    See Also:
    Serialized Form
    • Method Detail

      • getTimestamp

        public java.time.Instant getTimestamp()
        Returns:
        the timestamp of when this packet was captured.
      • getOriginalLength

        public int getOriginalLength()
        Returns:
        the original length of this packet.
      • getPacket

        public Packet getPacket()
        This method dissect the raw data.
        Returns:
        the captured packet.
      • length

        public int length()
        Get the length of the captured packet.
        Specified by:
        length in interface Packet
        Overrides:
        length in class AbstractPacket
        Returns:
        length
      • getRawData

        public byte[] getRawData()
        Get the raw data of the captured packet. This method doesn't do a defensive copy for performance reason.
        Specified by:
        getRawData in interface Packet
        Overrides:
        getRawData in class AbstractPacket
        Returns:
        raw data
      • getBuilder

        public PcapPacket.Builder getBuilder()
        Description copied from interface: Packet
        Returns a new Builder object populated with this object's fields' values.
        Specified by:
        getBuilder in interface Packet
        Specified by:
        getBuilder in class AbstractPacket
        Returns:
        a new Builder object populated with this object's fields values
      • buildString

        protected java.lang.String buildString()
        Description copied from class: AbstractPacket
        This method builds the value toString() will return by concatenating the header's string representation and the payload's string representation. If you write this subclass which represents a packet with extra parts (e.g. a trailer), you need to override this method.
        Overrides:
        buildString in class AbstractPacket
        Returns:
        a string representation of this object
      • toString

        public java.lang.String toString()
        Returns a string representation of the object. This method dissect the raw data.
        Overrides:
        toString in class AbstractPacket
      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from class: AbstractPacket
        Indicates whether some other object is "equal to" this one. This method firstly compares this packet's header using the header's equals(Object) method, then compares this packet's payload using the payload's equals(Object) method. If you write this subclass with fields which represent somethings other than header or payload, you need to override this method.
        Overrides:
        equals in class AbstractPacket
      • hashCode

        public int hashCode()
        Description copied from class: AbstractPacket
        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 AbstractPacket