bcds.tools
Class DataFileWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.BufferedWriter
          extended by bcds.tools.DataFileWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable
Direct Known Subclasses:
GZipFileWriter

public class DataFileWriter
extends java.io.BufferedWriter

Implements a line oriented file writer. All exceptions thrown are unchecked, of type AnyException. A file named "-" is interpreted as referencing System.out.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
DataFileWriter(java.lang.String fname)
          Creates an instance for writing to the file named fname.
DataFileWriter(java.io.Writer wr)
          Creates an instace for writing to wr with a default buffer size of 8 KB.
DataFileWriter(java.io.Writer wr, int buff_size)
          Creates an instace for writing to wr with the given buffer size.
 
Method Summary
 void flush()
          Flushes the output, catching any IOException.
 java.lang.String getFileName()
          Returns the filename this object is writing to.
static java.io.Writer newFileWriter(java.lang.String fname)
          Returns a new Writer.
 void printf(java.lang.String fmt, java.lang.Object... args)
          Prints formatted output.
 
Methods inherited from class java.io.BufferedWriter
close, newLine, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataFileWriter

public DataFileWriter(java.lang.String fname)
Creates an instance for writing to the file named fname.


DataFileWriter

public DataFileWriter(java.io.Writer wr)
Creates an instace for writing to wr with a default buffer size of 8 KB.


DataFileWriter

public DataFileWriter(java.io.Writer wr,
                      int buff_size)
Creates an instace for writing to wr with the given buffer size.

Method Detail

newFileWriter

public static java.io.Writer newFileWriter(java.lang.String fname)
Returns a new Writer. If fname is "-", returns an instace of OutputStreamWriter bound to System.out. Otherwise, returns a new java.io.FileWriter object.

Throws:
AnyException - wrapping an IOException is any IO error ocurrs.

flush

public void flush()
Flushes the output, catching any IOException.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.BufferedWriter
Throws:
AnyException - wrapping an IOException if an IO error occurs during the call to super.flush.

printf

public void printf(java.lang.String fmt,
                   java.lang.Object... args)
Prints formatted output. It is a convenience method that calls write(String.format(fmt, args)) and catches any IOException.

Throws:
AnyException - wrapping an IOException if any IO error occurs.

getFileName

public java.lang.String getFileName()
Returns the filename this object is writing to. It is null unless the constructor used was DataFileWriter(String).