Parsing Engine

danbikel.parser
Class EventCountsWriter

java.lang.Object
  extended byjava.io.Writer
      extended byjava.io.PrintWriter
          extended bydanbikel.parser.EventCountsWriter
All Implemented Interfaces:
ObjectWriter

public class EventCountsWriter
extends PrintWriter
implements ObjectWriter

Provides a method to write CountsTable objects containing counts of TrainerEvent objects to a file or an output stream. As an implementation of ObjectWriter, instances of this class may be used by the Switchboard to write such counts tables to an output file; such counts table objects are the output of the EMParser class. The switchboard will use instances of this class when an EventCountsWriterFactory is passed as an argument to one of the Switchboard constructors.

Implementation note: While historically the output of one or more EM parsing clients (EMParser instances) was fed to instances of this class, the current approach is to use the more flexible Consumer mechanism of the switchboard. Both EMParser (in stand-alone mode) and StartEMSwitchboard create an instance of a EventCountsConsumer in order to take the CountsTable objects produced by the EMParser and output them to an output file. However, this class is neither obsolete nor is its use deprecated. In fact, the EventCountsConsumer class makes use of the static method outputEvents(CountsTable,Writer) of this class.

See Also:
EventCountsConsumer, Switchboard.registerConsumer(Consumer)

Field Summary
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
EventCountsWriter(OutputStream os)
          Constructs a new EventCountsWriter using the specified output stream to output CountsTable instances containing counts of TrainerEvent objects.
EventCountsWriter(OutputStream os, String encoding, int bufSize)
          Constructs a new EventCountsWriter using the specified output stream, encoding and buffer size to output CountsTable instances containing counts of TrainerEvent objects.
EventCountsWriter(String filename, String encoding, int bufSize, boolean append)
          Constructs a new EventCountsWriter by creating a Writer for the specified filename, using the specified encoding, buffer size and append options.
 
Method Summary
static void outputEvents(CountsTable events, Writer out)
          A helper method used both by writeObject(Object) and by the EventCountsConsumer class to write a CountsTable with TrainerEvent keys as text to a Writer.
 void writeObject(Object obj)
          Writes the specified object to the file or output stream associated with this EventCountsWriter.
 
Methods inherited from class java.io.PrintWriter
checkError, close, flush, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface danbikel.switchboard.ObjectWriter
close
 

Constructor Detail

EventCountsWriter

public EventCountsWriter(OutputStream os)
Constructs a new EventCountsWriter using the specified output stream to output CountsTable instances containing counts of TrainerEvent objects.

Parameters:
os - the output stream to use for outputting CountsTables of TrainerEvents

EventCountsWriter

public EventCountsWriter(OutputStream os,
                         String encoding,
                         int bufSize)
                  throws IOException
Constructs a new EventCountsWriter using the specified output stream, encoding and buffer size to output CountsTable instances containing counts of TrainerEvent objects.

Parameters:
os - the output stream to use for outputting CountsTables of TrainerEvents
encoding - the encoding to use when constructing a Writer around the specified output stream
bufSize - the buffer size to use when constructing a BufferedWriter around the writer constructed around the specified output stream
Throws:
IOException - if there is an IOException thrown when creating any of the Writer instances around the specified output stream

EventCountsWriter

public EventCountsWriter(String filename,
                         String encoding,
                         int bufSize,
                         boolean append)
                  throws IOException
Constructs a new EventCountsWriter by creating a Writer for the specified filename, using the specified encoding, buffer size and append options.

Parameters:
filename - the filename for which to construct a Writer
encoding - the encoding for the Writer that is to be constructed for the specified file
bufSize - the buffer size for the BufferedWriter that is to be constructed around the Writer for the specified file
append - indicates whether to append to the specified file or to clobber any existing file and write anew
Throws:
IOException - if any of the constructors for the various Writer objects throw an IOException
Method Detail

writeObject

public void writeObject(Object obj)
                 throws IOException
Writes the specified object to the file or output stream associated with this EventCountsWriter.

Specified by:
writeObject in interface ObjectWriter
Parameters:
obj - a CountsTable instance whose keys are TrainerEvent instances
Throws:
IOException - if the underlying output writer or stream throws an IOException while writing out the specified object

outputEvents

public static void outputEvents(CountsTable events,
                                Writer out)
                         throws IOException
A helper method used both by writeObject(Object) and by the EventCountsConsumer class to write a CountsTable with TrainerEvent keys as text to a Writer. The text file written is both human- and machine-readable: it is crucially in the format written and read by the Trainer class.

Parameters:
events - the TrainerEvent counts to be written to the specified writer
out - the writer to which to write the specified TrainerEvent counts table
Throws:
IOException - if the specified output writer throws an IOException while writing out the specified CountsTable
See Also:
Trainer.writeStats(java.io.File), Trainer.readStats(java.io.File)

Parsing Engine

Author: Dan Bikel.