jAER project on SourceForge

ch.unizh.ini.jaer.projects.stereo3D
Class AE3DFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.DataInputStream
              extended by ch.unizh.ini.jaer.projects.stereo3D.AE3DFileInputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput

public class AE3DFileInputStream
extends java.io.DataInputStream

Class to stream in packets of events from binary input stream from a file recorded by 3D reconstructing filters.

File format is very simple: two adresses for left and right retina + timestamp

 int32 x
int32 y
int32 z
float value
int32 timestamp

An optional header consisting of lines starting with '#' is skipped when opening the file and may be retrieved. No later comment lines are allowed because the rest ot the file must be pure binary data.

AE3DFileInputStream has PropertyChangeSupport via getSupport(). PropertyChangeListeners will get informed of the following events

Author:
tobi

Nested Class Summary
 class AE3DFileInputStream.NonMonotonicTimeException
          class used to signal a backwards read from input stream
 class AE3DFileInputStream.WrappedTimeException
          Indicates that timestamp has wrapped around from most positive to most negative signed value.
 
Field Summary
static int CHUNK_SIZE_BYTES
          the size of the memory mapped part of the input file.
static int EVENT_SIZE
           
protected  java.util.ArrayList<java.lang.String> header
           
static int MAX_BUFFER_SIZE_EVENTS
           
 int MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT
           
 
Constructor Summary
AE3DFileInputStream(java.io.File f)
          Creates a new instance of AEInputStream
AE3DFileInputStream(java.io.FileInputStream in)
          Deprecated. use the constructor with a File object so that users of this can more easily get file information
 
Method Summary
 void close()
           
 AEFileInputStream copy()
          copies out the part of the stream from IN to OUT markers and returns it as a new AEInputStream
 AEFileInputStream cut()
          cuts out the part of the stream from IN to OUT and returns it as a new AEInputStream
 long getAbsoluteStartingTimeMs()
          When the file is opened, the filename is parsed to try to extract the date and time the file was created from the filename.
 int getCurrentStartTimestamp()
           
 int getDurationUs()
           
 java.io.File getFile()
          Returns the File that is being read, or null if the instance is constructed from a FileInputStream
 int getFirstTimestamp()
          returns the first timestamp in the stream
 float getFractionalPosition()
          Returns the position as a fraction of the total number of events
 java.util.ArrayList<java.lang.String> getHeader()
          Gets the header strings from the file
 int getLastTimestamp()
           
 int getMostRecentTimestamp()
           
 java.beans.PropertyChangeSupport getSupport()
          AEFileInputStream has PropertyChangeSupport.
 void mark()
          mark the current position.
 void markIn()
          mark the current position as the IN point for editing.
 void markOut()
          mark the current position as the OUT position for editing.
 void paste(AEFileInputStream in)
          pastes the in stream at the IN marker into this stream
 int position()
          gets the current position for reading forwards, i.e., readEventForwards will read this event number.
 void position(int event)
          set position in events from start of file
protected  void readHeader()
          reads the header comment lines.
 AEPacket3D readPacketByNumber(int n)
          Uesd to read fixed size packets.
 AEPacket3D readPacketByTime(int dt)
          returns an AEPacketRaw at least dt long up to the max size of the buffer or until end-of-file.
 void rewind()
          rewind to the start, or to the marked position, if it has been set.
 void setAbsoluteStartingTimeMs(long absoluteStartingTimeMs)
           
 void setCurrentStartTimestamp(int currentStartTimestamp)
           
 void setFile(java.io.File f)
          Sets the File reference but doesn't open the file
 void setFractionalPosition(float frac)
          Sets fractional position in events
 void setMostRecentTimestamp(int mostRecentTimestamp)
           
 long size()
          gets the size of the stream in events
protected  void skipHeader()
          skips the header lines (if any)
 java.lang.String toString()
           
 void unmark()
          clear any marked position
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT

public final int MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT
See Also:
Constant Field Values

MAX_BUFFER_SIZE_EVENTS

public static final int MAX_BUFFER_SIZE_EVENTS
See Also:
Constant Field Values

EVENT_SIZE

public static final int EVENT_SIZE
See Also:
Constant Field Values

CHUNK_SIZE_BYTES

public static final int CHUNK_SIZE_BYTES
the size of the memory mapped part of the input file. This window is centered over the file posiiton except at the start and end of the file.

See Also:
Constant Field Values

header

protected java.util.ArrayList<java.lang.String> header
Constructor Detail

AE3DFileInputStream

public AE3DFileInputStream(java.io.FileInputStream in)
Deprecated. use the constructor with a File object so that users of this can more easily get file information

Creates a new instance of AEInputStream


AE3DFileInputStream

public AE3DFileInputStream(java.io.File f)
                    throws java.io.FileNotFoundException
Creates a new instance of AEInputStream

Parameters:
f - the file to open
Throws:
java.io.FileNotFoundException - if file doesn't exist or can't be read
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

readPacketByNumber

public AEPacket3D readPacketByNumber(int n)
                              throws java.io.IOException
Uesd to read fixed size packets.

Parameters:
n - the number of events to read
Returns:
a raw packet of events of a specfied number of events fires a property change "position" on every call, and a property change "wrappedTime" if time wraps around.
Throws:
java.io.IOException

readPacketByTime

public AEPacket3D readPacketByTime(int dt)
                            throws java.io.IOException
returns an AEPacketRaw at least dt long up to the max size of the buffer or until end-of-file. Events are read as long as the timestamp until (and including) the event whose timestamp is greater (for dt>0) than startTimestamp+dt, where startTimestamp is the currentStartTimestamp. currentStartTimestamp is incremented after the call by dt. Fires a property change "position" on each call. Fires property change "wrappedTime" when time wraps from positive to negative or vice versa (when playing backwards).

Parameters:
dt - the timestamp different in units of the timestamp (usually us)
Throws:
java.io.IOException
See Also:
MAX_BUFFER_SIZE_EVENTS

rewind

public void rewind()
            throws java.io.IOException
rewind to the start, or to the marked position, if it has been set. Fires a property change "position" followed by "rewind".

Throws:
java.io.IOException

size

public long size()
gets the size of the stream in events

Returns:
size in events

position

public void position(int event)
set position in events from start of file

Parameters:
event - the number of the event, starting with 0

position

public int position()
gets the current position for reading forwards, i.e., readEventForwards will read this event number.

Returns:
position in events

getFractionalPosition

public float getFractionalPosition()
Returns the position as a fraction of the total number of events

Returns:
fractional position in total events

setFractionalPosition

public void setFractionalPosition(float frac)
Sets fractional position in events

Parameters:
frac - 0-1 float range, 0 at start, 1 at end

getSupport

public java.beans.PropertyChangeSupport getSupport()
AEFileInputStream has PropertyChangeSupport. This support fires events on certain events such as "rewind".


mark

public void mark()
          throws java.io.IOException
mark the current position.

Throws:
java.io.IOException - if there is some error in reading the data

markIn

public void markIn()
            throws java.io.IOException
mark the current position as the IN point for editing.

Throws:
java.io.IOException - if there is some error in reading the data

markOut

public void markOut()
             throws java.io.IOException
mark the current position as the OUT position for editing.

Throws:
java.io.IOException - if there is some error in reading the data

unmark

public void unmark()
clear any marked position


close

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

getFirstTimestamp

public int getFirstTimestamp()
returns the first timestamp in the stream

Returns:
the timestamp

getLastTimestamp

public int getLastTimestamp()
Returns:
last timestamp in file

getDurationUs

public int getDurationUs()
Returns:
the duration of the file in us.

Assumes data file is timestamped in us. This method fails to provide a sensible value if the timestamp wwaps.


getCurrentStartTimestamp

public int getCurrentStartTimestamp()
Returns:
the present value of the startTimestamp for reading data

setCurrentStartTimestamp

public void setCurrentStartTimestamp(int currentStartTimestamp)

getMostRecentTimestamp

public int getMostRecentTimestamp()
Returns:
returns the most recent timestamp

setMostRecentTimestamp

public void setMostRecentTimestamp(int mostRecentTimestamp)

cut

public AEFileInputStream cut()
cuts out the part of the stream from IN to OUT and returns it as a new AEInputStream

Returns:
the new stream

copy

public AEFileInputStream copy()
copies out the part of the stream from IN to OUT markers and returns it as a new AEInputStream

Returns:
the new stream

paste

public void paste(AEFileInputStream in)
pastes the in stream at the IN marker into this stream

Parameters:
in - the stream to paste

skipHeader

protected void skipHeader()
                   throws java.io.IOException
skips the header lines (if any)

Throws:
java.io.IOException

readHeader

protected void readHeader()
                   throws java.io.IOException
reads the header comment lines. Assumes we are rewound to position(0).

Throws:
java.io.IOException

getHeader

public java.util.ArrayList<java.lang.String> getHeader()
Gets the header strings from the file

Returns:
list of strings, one per line

getFile

public java.io.File getFile()
Returns the File that is being read, or null if the instance is constructed from a FileInputStream


setFile

public void setFile(java.io.File f)
Sets the File reference but doesn't open the file


getAbsoluteStartingTimeMs

public long getAbsoluteStartingTimeMs()
When the file is opened, the filename is parsed to try to extract the date and time the file was created from the filename.

Returns:
the time logging was started in ms since 1970

setAbsoluteStartingTimeMs

public void setAbsoluteStartingTimeMs(long absoluteStartingTimeMs)

jAER project on SourceForge