Class PcapngOutput

  • All Implemented Interfaces:
    IPcapOutput, java.io.Closeable, java.lang.AutoCloseable

    public class PcapngOutput
    extends java.lang.Object
    implements IPcapOutput
    Pcapng implementation of the output stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      PcapngOutput​(java.io.File f)
      Creates the output stream for the pcapng.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the output stream.
      void writeEnhancedPacketBlock​(int interfaceId, long timestamp, byte[] data)
      Writes enhanced packet block.
      void writeInterfaceDescriptionBlock​(LinkType linkType, int timestampResolution)
      Writes an interface description block.
      void writeSectionHeaderBlock​(java.lang.String hardware, java.lang.String osName, java.lang.String applicationName)
      Writes a section header block.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PcapngOutput

        public PcapngOutput​(java.io.File f)
                     throws java.io.IOException
        Creates the output stream for the pcapng.
        Parameters:
        f - File to write into.
        Throws:
        java.io.IOException - in case of failures with underlying operations.
    • Method Detail

      • writeInterfaceDescriptionBlock

        public void writeInterfaceDescriptionBlock​(LinkType linkType,
                                                   int timestampResolution)
                                            throws java.io.IOException
        Writes an interface description block. You MUST write one of those before you write enhanced packet block.
        Specified by:
        writeInterfaceDescriptionBlock in interface IPcapOutput
        Parameters:
        linkType - Link type for the block.
        timestampResolution - Timestamp resolution for the block. See Pcap.RESOLUTION_* constants.
        Throws:
        java.io.IOException - in case of errors with underlying IO operations
      • writeEnhancedPacketBlock

        public void writeEnhancedPacketBlock​(int interfaceId,
                                             long timestamp,
                                             byte[] data)
                                      throws java.io.IOException
        Writes enhanced packet block.
        Specified by:
        writeEnhancedPacketBlock in interface IPcapOutput
        Parameters:
        interfaceId - Interface id of this packet. The interface description block with a given interface id had to exist earlier in the file.
        timestamp - Timestamp in nanoseconds.
        data - Payload of the packet.
        Throws:
        java.io.IOException - in case of errors with underlying IO operations.
      • writeSectionHeaderBlock

        public void writeSectionHeaderBlock​(java.lang.String hardware,
                                            java.lang.String osName,
                                            java.lang.String applicationName)
                                     throws java.io.IOException
        Writes a section header block.
        Parameters:
        hardware - String describing hardware used for creating this file.
        osName - String describing operating system used in creation of this file.
        applicationName - Name of the application creating the PCAPNG file.
        Throws:
        java.io.IOException - in case of underlying IO exceptions.
      • close

        public void close()
                   throws java.io.IOException
        Closes the output stream.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException