org.strbio.io
Class PrintfStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.BufferedOutputStream
              extended by org.strbio.io.PrintfStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, Printf

public class PrintfStream
extends java.io.BufferedOutputStream
implements Printf

A BufferedOutputStream that you can do printf() on, like a civilized (C) programmer.

Features:

Bugs:
  Version 1.12, 3/29/99 - fixed bug:  "\n" treated as 1 char instead of
    two.
  Version 1.11, 6/18/98 - fixed bug with double/float and precision 1.
  Version 1.1, 5/5/98 - handles multi-digit precision and width.  Now
    handles precision for ints and longs (zero padding) and chars (ignored).
  Version 1.0, 4/24/98 - original version.
  

Version:
1.12, 3/29/99
Author:
JMC

Field Summary
static byte[] EOL
          The end of line character(s) on this system.
 
Fields inherited from class java.io.BufferedOutputStream
buf, count
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
PrintfStream(java.io.OutputStream os)
          Attaches to an OutputStream, such as System.out or System.err
PrintfStream(java.lang.String fileName)
          Open up a new file with a given name.
PrintfStream(java.lang.String fileName, boolean append)
          Open up a file with a given name.
 
Method Summary
 void newLine()
          Print a newline to the output, in a system-independent manner.
 void printf(java.lang.String fmt)
          Prints a string to the output, without any parameter substitution, but with formatting (i.e.
 void printf(java.lang.String fmt, char x)
          Prints a char to the output, with formatting.
 void printf(java.lang.String fmt, double x)
          Prints a double to the output, with formatting.
 void printf(java.lang.String fmt, float x)
          Prints a float to the output, with formatting.
 void printf(java.lang.String fmt, int x)
          Prints a int to the output, with formatting.
 void printf(java.lang.String fmt, long x)
          Prints a long to the output, with formatting.
 void printf(java.lang.String fmt, java.lang.String x)
          Prints a String to the output, with formatting.
 
Methods inherited from class java.io.BufferedOutputStream
flush, write, write
 
Methods inherited from class java.io.FilterOutputStream
close, 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
 

Field Detail

EOL

public static final byte[] EOL
The end of line character(s) on this system.

Constructor Detail

PrintfStream

public PrintfStream(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

PrintfStream

public PrintfStream(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

PrintfStream

public PrintfStream(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:
OutputStream
Method Detail

printf

public final void printf(java.lang.String fmt)
                  throws java.io.IOException
Prints a string to the output, without any parameter substitution, but with formatting (i.e. \n, %%).

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

newLine

public final void newLine()
                   throws java.io.IOException
Print a newline to the output, in a system-independent manner.

Throws:
java.io.IOException

printf

public final void printf(java.lang.String fmt,
                         int x)
                  throws java.io.IOException
Prints a int to the output, with formatting. This is about 10x faster than printing a long.

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,
                         long x)
                  throws java.io.IOException
Prints a long to the output, with 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,
                         char x)
                  throws java.io.IOException
Prints a char to the output, with 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 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 (i.e %-3s) it's ususally faster to use the + operator.
x - The String to print.
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 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 formatting. This is about 10x faster than printing a double.

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