org.jlab.coda.jevio
Class ByteParser

java.lang.Object
  extended by org.jlab.coda.jevio.ByteParser

public class ByteParser
extends java.lang.Object

This class controls the creating of an event by the parsing of a byte array. Unlike the EventParser class, it does not use a singleton pattern because the parsing of bytes is used primarily for reading data sent over the network or from an ET system and is used in a multithreaded environment. This class acts like EvioFile and EventParser together, except the data in our case is obtained by reading IO streams (eg. from a socket). Thus, it's much simpler than reading a file and the result is we have a byte array to parse.

Author:
timmer

Constructor Summary
ByteParser()
          No-arg constructor.
 
Method Summary
 void addEvioListener(IEvioListener listener)
          Add an Evio listener.
 boolean isNotificationActive()
          Get the flag determining whether notification of listeners is active.
 EvioEvent parseEvent(byte[] bytes, java.nio.ByteOrder byteOrder)
          This is the workhorse method for parsing the byte array.
 EvioEvent parseEvent(java.nio.ByteBuffer buf)
          This is the workhorse method for parsing the byte buffer.
 EvioEvent readEvent(java.io.DataInputStream in, java.nio.ByteOrder byteOrder)
          This is a method for reading data over a DataInputStream and parsing it into an EvioEvent.
 void removeEvioListener(IEvioListener listener)
          Remove an Evio listener.
 void setEvioFilter(IEvioFilter evioFilter)
          Set the global filter used for filtering structures.
 void setNotificationActive(boolean notificationActive)
          Set the flag determining whether notification of listeners is active.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteParser

public ByteParser()
No-arg constructor.

Method Detail

parseEvent

public EvioEvent parseEvent(byte[] bytes,
                            java.nio.ByteOrder byteOrder)
                     throws EvioException
This is the workhorse method for parsing the byte array. It will drill down and uncover all structures (banks, segments, and tagsegments) and notify any interested listeners in a SAX-Like manner.
Note: applications may choose not to provide a listener. In that case, when the event is parsed, its structures may be accessed through the event's tree model, i.e., via event.getTreeModel().

Parameters:
bytes - the binary data to be parsed.
byteOrder - the byte order of the binary array, either ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
an EvioEvent object created from the byte array.
Throws:
EvioException - if data not in evio format.

parseEvent

public EvioEvent parseEvent(java.nio.ByteBuffer buf)
                     throws EvioException
This is the workhorse method for parsing the byte buffer. It will drill down and uncover all structures (banks, segments, and tagsegments) and notify any interested listeners in a SAX-Like manner.
Note: applications may choose not to provide a listener. In that case, when the event is parsed, its structures may be accessed through the event's tree model, i.e., via event.getTreeModel().

Parameters:
buf - buffer of binary data to parse.
Returns:
an EvioEvent object created from the byte array.
Throws:
EvioException - if data not in evio format.

readEvent

public EvioEvent readEvent(java.io.DataInputStream in,
                           java.nio.ByteOrder byteOrder)
                    throws java.io.IOException,
                           EvioException
This is a method for reading data over a DataInputStream and parsing it into an EvioEvent.

Parameters:
in - data input stream containing binary data to parse in network byte order.
byteOrder - the byte order of the input bytes, either ByteOrder.BIG_ENDIAN or ByteOrder.LITTLE_ENDIAN.
Returns:
an EvioEvent object created from the data input stream.
Throws:
java.io.IOException - if IO error.
EvioException - if data not in evio format.

removeEvioListener

public void removeEvioListener(IEvioListener listener)
Remove an Evio listener. Evio listeners listen for structures encountered when an event is being parsed.

Parameters:
listener - The Evio listener to remove.

addEvioListener

public void addEvioListener(IEvioListener listener)
Add an Evio listener. Evio listeners listen for structures encountered when an event is being parsed.

Parameters:
listener - The Evio listener to add.

isNotificationActive

public boolean isNotificationActive()
Get the flag determining whether notification of listeners is active. Normally it is. But in some cases it should be temporarily suspended. For example, in a "goto event" process, the listeners will not be notified of the intervening events as the file is scanned to get to the target event.

Returns:
true if notification of events to the listeners is active.

setNotificationActive

public void setNotificationActive(boolean notificationActive)
Set the flag determining whether notification of listeners is active. Normally it is. But in some cases it should be temporarily suspended. For example, in a "goto event" process, the listeners will not be notified of the intervening events as the file is scanned to get to the target event.

Parameters:
notificationActive - set true if notification of events to the listeners is active.

setEvioFilter

public void setEvioFilter(IEvioFilter evioFilter)
Set the global filter used for filtering structures. If set to null, the default, then all structures will be sent to the listeners.

Parameters:
evioFilter - the filter to set.
See Also:
IEvioFilter