danbikel.parser
Class EventCountsWriter
java.lang.Object
java.io.Writer
java.io.PrintWriter
danbikel.parser.EventCountsWriter
- All Implemented Interfaces:
- ObjectWriter, Closeable, Flushable, Appendable
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)
| Methods inherited from class java.io.PrintWriter |
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, 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 |
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 TrainerEventsencoding - the encoding to use when constructing a Writer
around the specified output streambufSize - 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 Writerencoding - the encoding for the Writer that is to be
constructed for the specified filebufSize - the buffer size for the BufferedWriter that is to
be constructed around the Writer for the specified
fileappend - 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
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 writerout - 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)
Author: Dan Bikel.