jpcapwriter.java

来自「在windows下使用时先安装winpcap」· Java 代码 · 共 40 行

JAVA
40
字号
package jpcap;

import jpcap.packet.Packet;

/** This class is used to save the captured packets into a file. */
public class JpcapWriter
{
	private native String nativeOpenDumpFile(String filename,int ID);
	
	private JpcapWriter(JpcapCaptor jpcap,String filename)
			throws java.io.IOException{
		String ret=nativeOpenDumpFile(filename,jpcap.ID);
		
		if(ret!=null){ //error
			throw new java.io.IOException(ret);
		}
	}
	
	/** Opens a file to save the captured packets.
     * @param jpcap instance of Jpcap that was used to capture (load) packets
     * @param filename filename
     * @throws IOException If the file cannot be opened
     */
	public static JpcapWriter openDumpFile(JpcapCaptor jpcap,String filename) throws java.io.IOException{
		return new JpcapWriter(jpcap,filename);
	}
	
	/** Closes the opened file. */
	public native void close();
	
	/** Saves a packet into the file.
         * @param packet Packet to be saved
         */
	public native void writePacket(Packet packet);
	
  static{
    System.loadLibrary("jpcap");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?