edu.nps.moves.disutil
Class ConcatenatedDisPdus

java.lang.Object
  extended by edu.nps.moves.disutil.ConcatenatedDisPdus

public class ConcatenatedDisPdus
extends java.lang.Object

Reads concatenated PDUs, not necessarily of the same type or the same length, from a binary file. The assumption is that the PDUs were placed in IEEE format, concatenated one after the other, into the file.

It's not uncommonn to place serveral PDUs in a single datagram packet, since placing one in each datagram can cause a very heavy network load. This class is useful for extracting the PDUs from that one big byte array. It's also not uncommon to see people simply write out IEEE PDUs in a file, one after the other. It's a useful format, but then you need to read it back, which is what this does.

This also includes an "index" method that returns a big array with the input stream pointer position of the start of each PDU. This is useful for indexing into the input stream for semi-random access to PDUs in the stream.

This class is too profliigate with memory and should be rewritten to take advantage of some NIO classes.

Author:
DMcG

Constructor Summary
ConcatenatedDisPdus(java.io.InputStream is)
           
 
Method Summary
 java.util.List<Pdu> getAllPdus()
          Returns a List of all the PDUs remaining in the input stream
 PduContainer getAllPdusInPduContainer()
          Returns all the PDUs in the concatenated PDU input stream, starting with the current file position.
 int[] getIndexes()
          Returns an array of all the index positions in the input stream that are the starting points for each PDU.
 Pdu getNextPdu()
          Ugh--this is memory inefficient and should be rewritten so that the PDU factory can simply take an input stream.
static void main(java.lang.String[] args)
          Useful for some testing, maybe some example code
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcatenatedDisPdus

public ConcatenatedDisPdus(java.io.InputStream is)
Method Detail

getNextPdu

public Pdu getNextPdu()
Ugh--this is memory inefficient and should be rewritten so that the PDU factory can simply take an input stream. This can probably be done via the MappedByteBuffer in nio.

Note that this will fail horribly if the length field is wrong, or if any one of the length fields before this was wrong.

This depends on the input stream being open and not reset through multiple calls to getNextPdu().


getAllPdusInPduContainer

public PduContainer getAllPdusInPduContainer()
Returns all the PDUs in the concatenated PDU input stream, starting with the current file position.

Returns:
a PduContainer with all the pdus remainig in the input stream

getAllPdus

public java.util.List<Pdu> getAllPdus()
Returns a List of all the PDUs remaining in the input stream

Returns:
List of all the PDUs remaining

getIndexes

public int[] getIndexes()
Returns an array of all the index positions in the input stream that are the starting points for each PDU. Once this has been done, if you want to read PDUs at the indexes, you should close the input stream and re-open it so that the position pointer is at zero. Or, if the stream supports it, reset the pointer position to zero.

Returns:
array of ints, each entry the starting point (in bytes) of a PDU

main

public static void main(java.lang.String[] args)
Useful for some testing, maybe some example code

Parameters:
args -