jnetpcap.capture
Class CaptureOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by jnetpcap.capture.CaptureOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, CapturePacketOutput

public class CaptureOutputStream
extends java.io.OutputStream
implements CapturePacketOutput, java.io.Closeable, java.io.Flushable

A CaptureOutputStream writes CapturePackets to an OutputStream. The CapturePacket objects can be read (reconstituted) using an CaptureInputStream. Persistent storage of CapturePackets can be accomplished by using a file for a stream. If the stream is a network socket stream, the CapturePackets can be reconstitued on a nother host or in another process.

Here is an example:

 FileOutputStream fos = new FileOutputStream("test.stream");
 CaptureOutputStream cos = new CaptureOutputStream(fos);
 
 CapturePacket packet = // gotten from live network or file 
 cos.writePacket(packet);
 cos.close();
 
 FileInputStream fis = new FileInputStream("test.stream", "r");
 CaptureInputStream cis = new CaptureInputStream(fis);
 
 packet = cis.readPacket();
 cis.close();
 

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
CaptureOutputStream(java.io.OutputStream out)
           
 
Method Summary
 void close()
           
 void flush()
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writePacket(CapturePacket packet)
          Write a CapturePacket to the underlying storage or stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CaptureOutputStream

public CaptureOutputStream(java.io.OutputStream out)
                    throws java.io.IOException
Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

writePacket

public void writePacket(CapturePacket packet)
                 throws java.io.IOException
Description copied from interface: CapturePacketOutput
Write a CapturePacket to the underlying storage or stream. The class that implements this interface defines how the object is written.

Specified by:
writePacket in interface CapturePacketOutput
Parameters:
packet - the packet to be written
Throws:
java.io.IOException - any of the usual Input/Output related exceptions