com.voytechs.jnetstream.io
Class PcapOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.voytechs.jnetstream.io.ProtocolDataOutputStream
          extended by com.voytechs.jnetstream.io.PacketOutputStream
              extended by com.voytechs.jnetstream.io.CaptureOutputStream
                  extended by com.voytechs.jnetstream.io.PcapOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class PcapOutputStream
extends CaptureOutputStream

Output stream which writes out a capture file in PCAP format. If the InputStream is also a PCAP stream, then all original PCAP header information is copied into the new OutputStream. Otherwise all parameters of the new PcapOutputStream are created from scratch (i.e. the latest support file format, instead of the original version of PCAP found in InputStream.)

These examples demonstrates how InputStream and OutputStream can be used to copy between files.

First example is a simple copy. No format or file version conversion is done:

 PacketInputStream in = new PcapInputStream("oldfile.pcap");
 PacketOutputStream out = new PcapOutputStream("newfile.pcap", in); // get META from 'in'


Field Summary
protected  java.lang.String FORMAT_NAME
           
 
Fields inherited from class com.voytechs.jnetstream.io.ProtocolDataOutputStream
bitsLeft, cachedByte, out
 
Constructor Summary
PcapOutputStream(java.io.OutputStream out)
          Uses the given output stream to write new capture file.
PcapOutputStream(java.lang.String file)
          uses the given file to write new capture file.
 
Method Summary
 void initPacketStream()
          Write out the main capture file header into the capture stream.
static void main(java.lang.String[] args)
          Test function for PcapOutputStream
protected  void writeRecordHeader(long captureSecs, int captureNanos, long snaplen, long length)
          Write out the record header into the capture stream.
 
Methods inherited from class com.voytechs.jnetstream.io.CaptureOutputStream
close, copy, nextPacket, nextPacket
 
Methods inherited from class com.voytechs.jnetstream.io.PacketOutputStream
write
 
Methods inherited from class com.voytechs.jnetstream.io.ProtocolDataOutputStream
flush, unloadCachedByte, write, write, write, writeByte, writeInt, writeL, writeLByte, writeLInt, writeLLong, writeLong, writeLShort, writeShort, writeUByte, writeUInt, writeULByte, writeULInt, writeULLong, writeULong, writeULShort, writeUShort
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_NAME

protected java.lang.String FORMAT_NAME
Constructor Detail

PcapOutputStream

public PcapOutputStream(java.io.OutputStream out)
                 throws java.io.IOException,
                        StreamFormatException
Uses the given output stream to write new capture file. No META data is extracted.

Parameters:
out - Output stream to new capture file.
Throws:
java.io.IOException
StreamFormatException

PcapOutputStream

public PcapOutputStream(java.lang.String file)
                 throws java.io.FileNotFoundException,
                        java.io.IOException,
                        StreamFormatException
uses the given file to write new capture file. No META data is extracted.

Parameters:
file - Filename of the output capture file.
Throws:
FileNotFound - If file can not be opened.
java.io.FileNotFoundException
java.io.IOException
StreamFormatException
Method Detail

initPacketStream

public void initPacketStream()
                      throws java.io.IOException
Write out the main capture file header into the capture stream.

Specified by:
initPacketStream in class CaptureOutputStream
Throws:
java.io.IOException - Any I/O errors while writting the header.

writeRecordHeader

protected void writeRecordHeader(long captureSecs,
                                 int captureNanos,
                                 long snaplen,
                                 long length)
                          throws java.io.IOException
Write out the record header into the capture stream.

Specified by:
writeRecordHeader in class CaptureOutputStream
Throws:
java.io.IOException - Any I/O errors while writting the header.

main

public static void main(java.lang.String[] args)
Test function for PcapOutputStream

Parameters:
args - command line arguments