com.voytechs.jnetstream.io
Class RawformatInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.voytechs.jnetstream.io.ProtocolDataInputStream
          extended by com.voytechs.jnetstream.io.PacketInputStream
              extended by com.voytechs.jnetstream.io.RawformatInputStream
All Implemented Interfaces:
CaptureMetaFormat, java.io.Closeable

public class RawformatInputStream
extends PacketInputStream
implements CaptureMetaFormat

This input stream, reads in a capture file and applies capture file definitions found in a NPL file to try to find the right definition for the capture file. Once found, that definition produces a set of extracted headers which contain properties. This object look up the values for those properties which define attributes such as capture timestamp, record lengths, packet information, link types, etc...

So if you have a new capture file format you can define your own definition in NPL and pass that definition to this capture file decoder which using those definitions extracts packet data which can be further parsed using another the NPL decoder.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.voytechs.jnetstream.io.PacketInputStream
PacketInputStream.BufferedHeader
 
Field Summary
protected  Packet captureFileHeader
           
protected  Packet captureRecordHeader
           
protected  Decoder decoder
          The decoder used to decode capture file headers.
static java.lang.String FILE_HEADER
           
static java.lang.String FILE_RECORDLEN
           
static java.lang.String FILE_TYPENAME
           
static java.lang.String INTERFACE_DROPS
           
static java.lang.String INTERFACE_ERROR
           
static java.lang.String INTERFACE_IN
           
static java.lang.String INTERFACE_OUT
           
static int MAX_PACKET_LENGTH
           
protected  CaptureMetaEnumerator meta
           
static java.lang.String PACKET_HEADER_POSTFIX
           
static java.lang.String PACKET_LENGTH
           
static java.lang.String PACKET_LINKTYPE
           
static java.lang.String PACKET_NANOS
           
static java.lang.String PACKET_SECONDS
           
static java.lang.String PACKET_SNAPLEN
           
protected  java.lang.String recordHeaderName
           
 
Fields inherited from class com.voytechs.jnetstream.io.PacketInputStream
captureDeviceArch, captureDeviceFilename, captureDeviceIp, captureDeviceOS, captureLive, debugHeaders, fileHeader, linkType, packetCaptureTimestamp, packetEnd, packetLength, packetSnaplen, packetStart, recordEnd, recordHeader, recordLength, recordStart, stackIn
 
Fields inherited from class com.voytechs.jnetstream.io.ProtocolDataInputStream
bitsLeft, in
 
Constructor Summary
RawformatInputStream(java.io.InputStream rawFileFormatInputStream)
          First decodes the raw input stream, which can be a file, use NPL format file definitions.
RawformatInputStream(java.io.InputStream rawFileFormatInputStream, java.util.List nplFormatFiles)
          First decodes the raw input stream, which can be a file, use NPL format file definitions.
RawformatInputStream(java.io.InputStream rawFileFormatInputStream, java.lang.String nplFormatFile)
          First decodes the raw input stream, which can be a file, use NPL format file definitions.
RawformatInputStream(java.lang.String captureFile)
           
RawformatInputStream(java.lang.String captureFile, java.util.List nplFormatFiles)
          First decodes capture file using NPL format file definitions.
RawformatInputStream(java.lang.String captureFile, java.lang.String nplFormatFile)
          First decodes capture file using NPL format file definitions.
 
Method Summary
protected  void extractValues(Packet captureHeader)
          Extract values from NPL variables found packetHeader in the capture file.
 Packet getCaptureFileHeader()
           
 java.lang.String getCaptureFormatName()
          Returns the name of the capture source.
 Packet getCaptureRecordHeader()
           
 java.util.Enumeration getMetaEnumeration()
          Returns META information about the capture source.
protected  void initPacketStream()
          Read stream ID data.
protected  void initRecordHeader()
          Read pre-packet header from stream.
 boolean isMetaDataSupported()
          Returns if META data is supported.
protected  void readFileHeader()
          Read any file headers from the capture file.
protected  void readRecordHeader()
          Read pre-packet header from stream.
 java.lang.String toString()
          Convert to string.
 
Methods inherited from class com.voytechs.jnetstream.io.PacketInputStream
bitsLeft, clear, getCaptureDeviceAddress, getCaptureDeviceArch, getCaptureDeviceFilename, getCaptureDeviceIp, getCaptureDeviceOS, getCaptureTimestamp, getFileFormatName, getFileHeader, getLinkType, getPacketEnd, getPacketLength, getPacketLengthRemaining, getPacketSnaplen, getPacketStart, getPaddingLength, getRecordEnd, getRecordHeader, getRecordHeaderLength, getRecordLength, getRecordStart, goToEndOfRecord, gotoMark, hasForceRead, hex, isCaptureLive, isCompressed, isDebugHeaders, isPacketReady, isReady, isReady, main, nextPacket, pop, position, printStream, push, push, read, setCaptureTimestamp, setCompressed, setDebugHeaders, setForceRead, setIncludePadding, setLinkType, setPacketLength, setPacketSnaplen, setPacketStart, setRecordLength, setRecordStart, skip
 
Methods inherited from class com.voytechs.jnetstream.io.ProtocolDataInputStream
readBits, readBitsLong, readBoolean, readByte, readerUnsignedLongLittleEndian, readFromPacket, readFromPacket, readInt, readIntLittleEndian, readLong, readLongLittleEndian, readShort, readShortLittleEndian, readUnsignedByte, readUnsignedInt, readUnsignedIntLittleEndian, readUnsignedLong, readUnsignedShort, readUnsignedShortLittleEndian, reThrow
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_HEADER

public static final java.lang.String FILE_HEADER
See Also:
Constant Field Values

PACKET_HEADER_POSTFIX

public static final java.lang.String PACKET_HEADER_POSTFIX
See Also:
Constant Field Values

MAX_PACKET_LENGTH

public static final int MAX_PACKET_LENGTH
See Also:
Constant Field Values

FILE_TYPENAME

public static final java.lang.String FILE_TYPENAME
See Also:
Constant Field Values

FILE_RECORDLEN

public static final java.lang.String FILE_RECORDLEN
See Also:
Constant Field Values

PACKET_LINKTYPE

public static final java.lang.String PACKET_LINKTYPE
See Also:
Constant Field Values

PACKET_LENGTH

public static final java.lang.String PACKET_LENGTH
See Also:
Constant Field Values

PACKET_SNAPLEN

public static final java.lang.String PACKET_SNAPLEN
See Also:
Constant Field Values

PACKET_SECONDS

public static final java.lang.String PACKET_SECONDS
See Also:
Constant Field Values

PACKET_NANOS

public static final java.lang.String PACKET_NANOS
See Also:
Constant Field Values

INTERFACE_DROPS

public static final java.lang.String INTERFACE_DROPS
See Also:
Constant Field Values

INTERFACE_IN

public static final java.lang.String INTERFACE_IN
See Also:
Constant Field Values

INTERFACE_OUT

public static final java.lang.String INTERFACE_OUT
See Also:
Constant Field Values

INTERFACE_ERROR

public static final java.lang.String INTERFACE_ERROR
See Also:
Constant Field Values

decoder

protected Decoder decoder
The decoder used to decode capture file headers.


recordHeaderName

protected java.lang.String recordHeaderName

captureFileHeader

protected Packet captureFileHeader

captureRecordHeader

protected Packet captureRecordHeader

meta

protected CaptureMetaEnumerator meta
Constructor Detail

RawformatInputStream

public RawformatInputStream(java.io.InputStream rawFileFormatInputStream)
                     throws java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
First decodes the raw input stream, which can be a file, use NPL format file definitions. Once the capture file is parsed into file and record headers, the records containing captured packets can be accessed using the PacketInputStream API which this object extends and implements all its interfaces.

By calling PacketInputStream.nextPacket() method, the capture file decoder advances to the next file record and gets the next packet ready for reading.

Parameters:
rawFileFormatInputStream - Stream containing the capture file.
nplFormatFile - Filename containing capture file format definitions.
Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.
SyntaxError - Any NPL syntax errors found in the capture format definitions file.

RawformatInputStream

public RawformatInputStream(java.io.InputStream rawFileFormatInputStream,
                            java.lang.String nplFormatFile)
                     throws java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
First decodes the raw input stream, which can be a file, use NPL format file definitions. Once the capture file is parsed into file and record headers, the records containing captured packets can be accessed using the PacketInputStream API which this object extends and implements all its interfaces.

By calling PacketInputStream.nextPacket() method, the capture file decoder advances to the next file record and gets the next packet ready for reading.

Parameters:
rawFileFormatInputStream - Stream containing the capture file.
nplFormatFile - Filename containing capture file format definitions.
Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.
SyntaxError - Any NPL syntax errors found in the capture format definitions file.

RawformatInputStream

public RawformatInputStream(java.io.InputStream rawFileFormatInputStream,
                            java.util.List nplFormatFiles)
                     throws java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
First decodes the raw input stream, which can be a file, use NPL format file definitions. Once the capture file is parsed into file and record headers, the records containing captured packets can be accessed using the PacketInputStream API which this object extends and implements all its interfaces.

By calling PacketInputStream.nextPacket() method, the capture file decoder advances to the next file record and gets the next packet ready for reading.

Parameters:
rawFileFormatInputStream - Stream containing the capture file.
nplFormatFiles - A list of filenames containing capture file format definitions.
Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.
SyntaxError - Any NPL syntax errors found in the capture format definitions file.

RawformatInputStream

public RawformatInputStream(java.lang.String captureFile)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
Throws:
java.io.FileNotFoundException
java.io.IOException
EOPacketStream
StreamFormatException
SyntaxError

RawformatInputStream

public RawformatInputStream(java.lang.String captureFile,
                            java.util.List nplFormatFiles)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
First decodes capture file using NPL format file definitions. Once the capture file is parsed into file and record headers, the records containing captured packets can be accessed using the PacketInputStream API which this object extends and implements all its interfaces.

By calling PacketInputStream.nextPacket() method, the capture file decoder advances to the next file record and gets the next packet ready for reading.

Parameters:
rawFileFormatInputStream - Stream containing the capture file.
nplFormatFile - Filename containing capture file format definitions.
Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.
SyntaxError - Any NPL syntax errors found in the capture format definitions file.
java.io.FileNotFoundException

RawformatInputStream

public RawformatInputStream(java.lang.String captureFile,
                            java.lang.String nplFormatFile)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            EOPacketStream,
                            StreamFormatException,
                            SyntaxError
First decodes capture file using NPL format file definitions. Once the capture file is parsed into file and record headers, the records containing captured packets can be accessed using the PacketInputStream API which this object extends and implements all its interfaces.

By calling PacketInputStream.nextPacket() method, the capture file decoder advances to the next file record and gets the next packet ready for reading.

Parameters:
rawFileFormatInputStream - Stream containing the capture file.
nplFormatFile - Filename containing capture file format definitions.
Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.
SyntaxError - Any NPL syntax errors found in the capture format definitions file.
java.io.FileNotFoundException
Method Detail

initPacketStream

protected void initPacketStream()
                         throws java.io.IOException,
                                EOPacketStream,
                                StreamFormatException
Description copied from class: PacketInputStream
Read stream ID data. This is only called once during the stream initialization and no more.

Overrides:
initPacketStream in class PacketInputStream
Throws:
java.io.IOException
EOPacketStream
StreamFormatException

readFileHeader

protected void readFileHeader()
                       throws java.io.IOException,
                              EOPacketStream,
                              StreamFormatException
Read any file headers from the capture file. Extracts all interested information and prepares to read a record header.

Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.

initRecordHeader

protected void initRecordHeader()
                         throws java.io.IOException,
                                EOPacketStream,
                                StreamFormatException
Description copied from class: PacketInputStream
Read pre-packet header from stream. With basic info about the next packet to follow. this is called for every packet in the stream. Main purpose is to get packet-data length (or length of captured packet) and the capture time of the packet.

Overrides:
initRecordHeader in class PacketInputStream
Throws:
java.io.IOException
EOPacketStream
StreamFormatException

readRecordHeader

protected void readRecordHeader()
                         throws java.io.IOException,
                                EOPacketStream,
                                StreamFormatException
Read pre-packet header from stream. With basic info about the next packet to follow. this is called for every packet in the stream. Main purpose is to get packet-data length (or length of captured packet) and the capture time of the packet.

Throws:
java.io.IOException - Any I/O errors.
EOPacketStream - If unexpected end of stream occures.
StreamFormatException - If capture files' format is not understood and an error occures.

extractValues

protected void extractValues(Packet captureHeader)
                      throws StreamFormatException
Extract values from NPL variables found packetHeader in the capture file.

Parameters:
captureHeader - Packet contains values of the capture header. The values are stored as regular fields. The field names are named such that this method can extract meaningfull values to parse the rest of the capture file.
Throws:
StreamFormatException - any problems with the capture file's headers.

toString

public java.lang.String toString()
Convert to string. NOT IMPLEMENTED YET, empty string is returned.

Overrides:
toString in class java.lang.Object
Returns:
Empty string.

getMetaEnumeration

public java.util.Enumeration getMetaEnumeration()
Returns META information about the capture source.

Specified by:
getMetaEnumeration in interface CaptureMetaFormat
Returns:
Enumerated set of META values

isMetaDataSupported

public boolean isMetaDataSupported()
Returns if META data is supported. RawformatInputStream supports META data, thus it always returns true.

Specified by:
isMetaDataSupported in interface CaptureMetaFormat
Returns:
true if META data is supported by this stream, normally all file based streams support META data.

getCaptureFormatName

public java.lang.String getCaptureFormatName()
Returns the name of the capture source. It is the header name assigned in the captureformat.npl file. I.e. if definition named SnoopV2 in the captureformat.npl file was used to parse the current source, the format name returned would be "SnoopV2".

Specified by:
getCaptureFormatName in interface CaptureMetaFormat
Returns:
name of the source format. If source format name is not known, an empty string is returned. This method never returns null.

getCaptureFileHeader

public Packet getCaptureFileHeader()
Returns:
Returns the captureFileHeader.

getCaptureRecordHeader

public Packet getCaptureRecordHeader()
Returns:
Returns the captureRecordHeader.