org.strbio.io
Class PrintfWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.BufferedWriter
          extended by org.strbio.io.PrintfWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable, Printf

public class PrintfWriter
extends java.io.BufferedWriter
implements Printf

A Writer that you can do printf() on, like a civilized (C) programmer. This uses the sprintf routines in StringUtil. These routines are not thread-safe.

  Version 1.22, 5/1/07 - added constructor for other Writers; moved
    tests to PrintfTest
  Version 1.21, 3/29/99 - fixed to use updated StringUtil routines.
  Version 1.2, 6/4/98 - uses my StringUtil class instead of corejava.
  Version 1.1, 4/7/98 - fixed misc bugs.
  Version 1.0, 4/2/98 - original version.
  

Version:
1.22, 5/1/07
Author:
JMC

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PrintfWriter(java.io.File file)
          Attaches to an open file?
PrintfWriter(java.io.FileDescriptor fd)
          This is inherited from FileWriter.
PrintfWriter(java.io.FileWriter fw)
          Attaches to an already open FileWriter.
PrintfWriter(java.io.OutputStream os)
          Attaches to an OutputStream, such as System.out or System.err
PrintfWriter(java.lang.String fileName)
          Open up a new file with a given name.
PrintfWriter(java.lang.String fileName, boolean append)
          Open up a file with a given name.
PrintfWriter(java.io.Writer w)
          Attaches to another Writer
 
Method Summary
 void printf(java.lang.String fmt)
          Prints a string to the output, without any formatting or parameter substitution (because there are no parameters)
 void printf(java.lang.String fmt, char x)
          Prints an integer to the output with some formatting.
 void printf(java.lang.String fmt, double x)
          Prints a double to the output with some formatting.
 void printf(java.lang.String fmt, float x)
          Prints a float to the output with some formatting.
 void printf(java.lang.String fmt, int x)
          Prints an integer to the output with some formatting.
 void printf(java.lang.String fmt, long x)
          Prints a long to the output with some formatting.
 void printf(java.lang.String fmt, java.lang.String x)
          Prints a String to the output with some formatting.
 
Methods inherited from class java.io.BufferedWriter
close, flush, 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
 
Methods inherited from interface org.strbio.io.Printf
flush
 

Constructor Detail

PrintfWriter

public PrintfWriter(java.lang.String fileName)
             throws java.io.IOException
Open up a new file with a given name. Will overwrite an existing file.

Throws:
java.io.IOException
See Also:
FileWriter

PrintfWriter

public PrintfWriter(java.lang.String fileName,
                    boolean append)
             throws java.io.IOException
Open up a file with a given name. If append is true, it appends to an existing file.

Throws:
java.io.IOException
See Also:
FileWriter

PrintfWriter

public PrintfWriter(java.io.File file)
             throws java.io.IOException
Attaches to an open file? This is inherited from FileWriter.

Throws:
java.io.IOException
See Also:
FileWriter

PrintfWriter

public PrintfWriter(java.io.FileWriter fw)
             throws java.io.IOException
Attaches to an already open FileWriter.

Throws:
java.io.IOException
See Also:
FileWriter

PrintfWriter

public PrintfWriter(java.io.FileDescriptor fd)
             throws java.io.IOException
This is inherited from FileWriter.

Throws:
java.io.IOException
See Also:
FileWriter

PrintfWriter

public PrintfWriter(java.io.OutputStream os)
             throws java.io.IOException
Attaches to an OutputStream, such as System.out or System.err

Throws:
java.io.IOException
See Also:
OutputStreamWriter, OutputStream

PrintfWriter

public PrintfWriter(java.io.Writer w)
             throws java.io.IOException
Attaches to another Writer

Throws:
java.io.IOException
See Also:
Writer
Method Detail

printf

public final void printf(java.lang.String fmt)
                  throws java.io.IOException
Prints a string to the output, without any formatting or parameter substitution (because there are no parameters)

Specified by:
printf in interface Printf
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         double x)
                  throws java.io.IOException
Prints a double to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %f or something to that effect. Note that you don't do %lf, just %f.
x - The double to print.
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         float x)
                  throws java.io.IOException
Prints a float to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %f or something to that effect.
x - The float to print.
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         long x)
                  throws java.io.IOException
Prints a long to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %d or something to that effect. Note that you don't do %ld, just %d.
x - The long to print.
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         int x)
                  throws java.io.IOException
Prints an integer to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %d or something to that effect.
x - The int to print.
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         char x)
                  throws java.io.IOException
Prints an integer to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %c or something to that effect.
x - The char to print.
Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         java.lang.String x)
                  throws java.io.IOException
Prints a String to the output with some formatting.

Specified by:
printf in interface Printf
Parameters:
fmt - The format string, like in C... should contain %s or something to that effect. Note that unless you actually do some formatting (e.g., %-3s) it's ususally faster to use the + operator.
x - The String to print.
Throws:
java.io.IOException