jnetpcap.capture
Class CaptureInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by jnetpcap.capture.CaptureInputStream
All Implemented Interfaces:
java.io.Closeable, CapturePacketInput

public class CaptureInputStream
extends java.io.InputStream
implements CapturePacketInput, java.io.Closeable

A CaptureInputStream deserializes CapturePackets into DeserializedPacket objects previously written using a CaptureOutputStream. DeserializedPacket interface is a subclass of CapturePacket which adds several new methods that contain information about the serialization 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");
 CaptureInputStream cis = new CaptureInputStream(fis);
 
 packet = cis.readPacket();
 cis.close();
 

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
CaptureInputStream(java.io.InputStream in)
          Creates an ObjectInputStream that reads from the specified InputStream.
 
Method Summary
 int available()
           
 void close()
           
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 DeserializedPacket readPacket()
          Read and return a StreamPacket object.
 void reset()
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CaptureInputStream

public CaptureInputStream(java.io.InputStream in)
                   throws java.io.IOException
Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding CapturePacketOutputStream has written and flushed the header.

Parameters:
in - input stream to read from
Throws:
java.io.IOException - any usual I/O errors
Method Detail

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

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

mark

public void mark(int readlimit)
Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.InputStream

read

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

read

public int read(byte[] b)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

readPacket

public DeserializedPacket readPacket()
                              throws java.io.IOException
Description copied from interface: CapturePacketInput
Read and return a StreamPacket object. The class that implements this interface defines where the object is "read" from.

Specified by:
readPacket in interface CapturePacketInput
Returns:
the CapturePacket object read from storage or stream
Throws:
java.io.IOException - if any of the usual InputOutput related exceptions occur