public final class PcapWriteHandler extends ChannelDuplexHandler implements java.io.Closeable
PcapWriteHandler
captures ByteBuf
from SocketChannel
/ ServerChannel
or DatagramPacket
and writes it into Pcap OutputStream
.
Things to keep in mind when using PcapWriteHandler
with TCP:
ChannelInboundHandlerAdapter.channelActive(ChannelHandlerContext)
is called,
a fake TCP 3-way handshake (SYN, SYN+ACK, ACK) is simulated as new connection in Pcap. ChannelHandlerAdapter.handlerRemoved(ChannelHandlerContext)
is called,
a fake TCP 3-way handshake (FIN+ACK, FIN+ACK, ACK) is simulated as connection shutdown in Pcap. ChannelInboundHandlerAdapter.exceptionCaught(ChannelHandlerContext, Throwable)
is called, a fake TCP RST is sent to simulate connection Reset in Pcap. captureZeroByte
to false
. 限定符和类型 | 类和说明 |
---|---|
static class |
PcapWriteHandler.Builder
Builder for
PcapWriteHandler |
ChannelHandler.Sharable
构造器和说明 |
---|
PcapWriteHandler(java.io.OutputStream outputStream)
已过时。
Use
PcapWriteHandler.Builder instead. |
PcapWriteHandler(java.io.OutputStream outputStream,
boolean captureZeroByte,
boolean writePcapGlobalHeader)
已过时。
Use
PcapWriteHandler.Builder instead. |
限定符和类型 | 方法和说明 |
---|---|
static PcapWriteHandler.Builder |
builder() |
void |
channelActive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelActive() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
close()
Close
PcapWriter and OutputStream . |
void |
exceptionCaught(ChannelHandlerContext ctx,
java.lang.Throwable cause)
Calls
ChannelHandlerContext.fireExceptionCaught(Throwable) to forward
to the next ChannelHandler in the ChannelPipeline . |
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isWriting()
Returns
true if the PcapWriteHandler is currently
writing packets to the OutputStream else returns false . |
void |
pause()
Pause the
PcapWriteHandler from writing packets to the OutputStream . |
void |
resume()
Resume the
PcapWriteHandler to writing packets to the OutputStream . |
java.lang.String |
toString() |
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline . |
static void |
writeGlobalHeader(java.io.OutputStream outputStream)
Writes the Pcap Global Header to the provided
OutputStream |
bind, close, connect, deregister, disconnect, flush, read
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
ensureNotSharable, handlerAdded, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
handlerAdded
@Deprecated public PcapWriteHandler(java.io.OutputStream outputStream)
PcapWriteHandler.Builder
instead.PcapWriteHandler
Instance.
captureZeroByte
is set to false
and
writePcapGlobalHeader
is set to true
.outputStream
- OutputStream where Pcap data will be written. Call close()
to close this
OutputStream.java.lang.NullPointerException
- If OutputStream
is null
then we'll throw an
NullPointerException
@Deprecated public PcapWriteHandler(java.io.OutputStream outputStream, boolean captureZeroByte, boolean writePcapGlobalHeader)
PcapWriteHandler.Builder
instead.PcapWriteHandler
InstanceoutputStream
- OutputStream where Pcap data will be written. Call close()
to close this
OutputStream.captureZeroByte
- Set to true
to enable capturing packets with empty (0 bytes) payload.
Otherwise, if set to false
, empty packets will be filtered out.writePcapGlobalHeader
- Set to true
to write Pcap Global Header on initialization.
Otherwise, if set to false
, Pcap Global Header will not be written
on initialization. This could when writing Pcap data on a existing file where
Pcap Global Header is already present.java.lang.NullPointerException
- If OutputStream
is null
then we'll throw an
NullPointerException
public static void writeGlobalHeader(java.io.OutputStream outputStream) throws java.io.IOException
OutputStream
outputStream
- OutputStream where Pcap data will be written.java.io.IOException
- if there is an error writing to the OutputStream
public void channelActive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelActive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelActive
在接口中 ChannelInboundHandler
channelActive
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
在接口中 ChannelInboundHandler
channelRead
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelDuplexHandler
ChannelOutboundInvoker.write(Object, ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
在接口中 ChannelOutboundHandler
write
在类中 ChannelDuplexHandler
ctx
- the ChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- the ChannelPromise
to notify once the operation completesjava.lang.Exception
- thrown if an error occurspublic void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
在接口中 ChannelHandler
handlerRemoved
在类中 ChannelHandlerAdapter
java.lang.Exception
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireExceptionCaught(Throwable)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.exceptionCaught
在接口中 ChannelHandler
exceptionCaught
在接口中 ChannelInboundHandler
exceptionCaught
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
public boolean isWriting()
true
if the PcapWriteHandler
is currently
writing packets to the OutputStream
else returns false
.public void pause()
PcapWriteHandler
from writing packets to the OutputStream
.public void resume()
PcapWriteHandler
to writing packets to the OutputStream
.public java.lang.String toString()
toString
在类中 java.lang.Object
public void close() throws java.io.IOException
Close PcapWriter
and OutputStream
.
Note: Calling this method does not close PcapWriteHandler
.
Only Pcap Writes are closed.
close
在接口中 java.io.Closeable
close
在接口中 java.lang.AutoCloseable
java.io.IOException
- If OutputStream.close()
throws an exceptionpublic static PcapWriteHandler.Builder builder()