SourceForge Jpcap

net.sourceforge.jpcap.capture
Class PacketOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by net.sourceforge.jpcap.capture.PacketOutputStream
All Implemented Interfaces:
Closeable, Flushable

public abstract class PacketOutputStream
extends OutputStream

PacketOutputStream is an I/O stream used for sending Packets to the network, or dumping them to a tcpdump-formatted file, depending on how the stream was created.

The close() and flush() methods close and flush the output file respectively. For a stream created for sending, they do nothing.

Since:
2.0.0
Version:
$Revision: 1.1 $
Author:
Esmond Pitt
See Also:
PacketCapture.captureTo(int, PacketOutputStream), PacketCapture.getOutputStream(), PacketCapture.getOutputStream(File)

Constructor Summary
protected PacketOutputStream()
          Creates a new instance of PacketOutputStream
 
Method Summary
abstract  long getFilePointer()
          Return the current file position for the savefile, i.e.
 void write(byte[] buffer)
          
 void write(byte[] buffer, int offset, int count)
          
 void write(int b)
          
abstract  void writePacket(Packet packet)
          Write a packet, by either: sending it to the network, or dumping it to a tcpdump-formatted output file, depending on how the stream was created.
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketOutputStream

protected PacketOutputStream()
Creates a new instance of PacketOutputStream

Method Detail

getFilePointer

public abstract long getFilePointer()
                             throws IOException
Return the current file position for the savefile, i.e. the number of bytes written by writePacket(net.sourceforge.jpcap.net.Packet).

Returns:
the current file position.
Throws:
IOException - Savefile not open, output not a savefile, etc.

write

public void write(int b)
           throws IOException

This implementation throws UnsupportedOperationException.

Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] buffer)
           throws IOException

This implementation throws UnsupportedOperationException.

Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] buffer,
                  int offset,
                  int count)
           throws IOException

This implementation throws UnsupportedOperationException.

Overrides:
write in class OutputStream
Throws:
IOException

writePacket

public abstract void writePacket(Packet packet)
                          throws IOException
Write a packet, by either: depending on how the stream was created. The packet is written after calling Packet.setChecksums(), so checksums &c are not the application's problem, at least for packet classes which correctly implement Packet.setChecksums().

Parameters:
packet - Packet to write.
Throws:
IOException - Some I/O problem sending or dumping the packet.

Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.