com.voytechs.jnetstream.io
Class PacketOutputStream

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

public abstract class PacketOutputStream
extends ProtocolDataOutputStream

Base class for OutputStreams that follow the Packetized structure.

PacketOutputStream is used to output to various CAPTURE stream or file formats, such as PCAP, SNOOP and other sniffer and protocol analyzer formats.



This stream enforces a structure on the stream where certain information about the capture streams can be set and then written out. This is a base class for upper layers that implement CAPTURE format specific OutputStream.



In addition, META data can be exchanged between PacketInputStream and PacketOutputStream which allows preservation of certain headers between the two. Example of this would be copying from one PCAP file to another while doing some filtering. The output file would be created in the same version of the file format as the source, minus any processing in between the two.

The main methods used to write data to this output stream are write() or copy(). The write() method writes one byte or individual bits at a time into the stream. Also the class extends the ProtocolDataInputStream base-class that defines write methods for each of the java primitives in both little and big endian encoding, signed and unsigned variables can written to the output stream.

The copy() is used to copy content from PacketInputStream to the outputstream. Depending which sub-class is used for the output stream, either the contents can be copied into a different capture file while changing formats or a straight copy into the same type of capture file.

Note: You will not find nextPacket() in this class. This functionality has been removed from this base class. Appropriate version of nextPacket() method is not implemented in sub-classes.

See Also:
DupPacketOutputStream, CaptureOutputStream

Field Summary
 
Fields inherited from class com.voytechs.jnetstream.io.ProtocolDataOutputStream
bitsLeft, cachedByte, out
 
Constructor Summary
PacketOutputStream(java.io.OutputStream out)
          Uses the given output stream to write out Packetized stream format.
PacketOutputStream(java.lang.String file)
          Uses the given output stream to write out Packetized stream format.
 
Method Summary
abstract  void copy(PacketInputStream in)
          Copy from PacketInputStream to another.
protected abstract  void initPacketStream()
          Initializes the main stream or file header.
static void main(java.lang.String[] args)
          Test function for PacketOutputStream
 void write(int b)
          Write a byte of data to the stream.
 
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
close, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketOutputStream

public PacketOutputStream(java.io.OutputStream out)
Uses the given output stream to write out Packetized stream format.

Parameters:
out - OutputStream to write our data.

PacketOutputStream

public PacketOutputStream(java.lang.String file)
                   throws java.io.FileNotFoundException
Uses the given output stream to write out Packetized stream format.

Throws:
java.io.FileNotFoundException
Method Detail

initPacketStream

protected abstract void initPacketStream()
                                  throws java.io.IOException,
                                         StreamFormatException
Initializes the main stream or file header.

Throws:
java.io.IOException
StreamFormatException

write

public void write(int b)
           throws java.io.IOException
Write a byte of data to the stream.

Overrides:
write in class ProtocolDataOutputStream
Parameters:
b - Byte to write to the stream.
Throws:
java.io.IOException - Any IO errors

copy

public abstract void copy(PacketInputStream in)
                   throws java.io.IOException,
                          StreamFormatException
Copy from PacketInputStream to another.

Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - Unexpected end of stream occures.
PrimitiveException - Any primitive compatibility errors.
StreamFormatException

main

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

Parameters:
args - command line arguments