Class Pcap


  • public class Pcap
    extends java.lang.Object
    Entry level API for pcap support.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isFileCorrectType​(java.io.File f)
      Returns true if this file is of a correct type.
      static IPcapInput openForReading​(java.io.File f)
      Opens a static file and returns the pcap stream.
      static IPcapOutput openForWriting​(java.io.File f)
      Creates a PCAPNG file for writing, using local defaults for hardware and OS name.
      static IPcapOutput openForWriting​(java.io.File f, java.lang.String hardware, java.lang.String osName, java.lang.String applicationName)
      Opens a file for writing.
      • Methods inherited from class java.lang.Object

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

      • RESOLUTION_MICROSECONDS

        public static final int RESOLUTION_MICROSECONDS
        Resolution in microseconds.
        See Also:
        Constant Field Values
      • RESOLUTION_NANOSECONDS

        public static final int RESOLUTION_NANOSECONDS
        Resolution in nanoseconds.
        See Also:
        Constant Field Values
      • PCAPNG_VERSION_MAJOR

        public static final int PCAPNG_VERSION_MAJOR
        Major version of pcapng written out by this library.
        See Also:
        Constant Field Values
      • PCAPNG_VERSION_MINOR

        public static final int PCAPNG_VERSION_MINOR
        Minor version of pcapng written out by this library.
        See Also:
        Constant Field Values
    • Method Detail

      • isFileCorrectType

        public static boolean isFileCorrectType​(java.io.File f)
        Returns true if this file is of a correct type.
        Parameters:
        f - File to use.
        Returns:
        True if this file can be read with this library.
      • openForWriting

        public static IPcapOutput openForWriting​(java.io.File f)
                                          throws java.io.IOException
        Creates a PCAPNG file for writing, using local defaults for hardware and OS name. It uses `java-pcap` as application name. If you wish to pass different value, use the other openForWriting() method.
        Parameters:
        f - File to use.
        Returns:
        Output object that can be used to add blocks to the file.
        Throws:
        java.io.IOException - from underlying IO operations.
      • openForWriting

        public static IPcapOutput openForWriting​(java.io.File f,
                                                 java.lang.String hardware,
                                                 java.lang.String osName,
                                                 java.lang.String applicationName)
                                          throws java.io.IOException
        Opens a file for writing.
        Parameters:
        f - File to use.
        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.
        Returns:
        Output object that can be used to add blocks to the file.
        Throws:
        java.io.IOException - from underlying IO operations.
      • openForReading

        public static IPcapInput openForReading​(java.io.File f)
                                         throws java.io.IOException
        Opens a static file and returns the pcap stream.
        Parameters:
        f - File to read.
        Returns:
        Input object that can be used to retrieve data.
        Throws:
        java.io.IOException - from underlying IO operations.