org.cip4.jdflib.cformat
Class PrintfStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.PrintStream
              extended by org.cip4.jdflib.cformat.PrintfStream
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class PrintfStream
extends PrintStream

PrintStream which outputs primitive types using C printf style formatting. For each primitive type (float, double, char, int, long, String), there is a printf method which takes (as a first argument) either a printf style format string, or a PrintfFormat object. Using the latter can be more efficient because it permits an application to prorate the overhead of parsing a format string.

Because Java does not permit variable numbers of arguments, each printf methodName accepts only one primitive type, and the format can correspondingly contain only one conversion sequence.

See Also:
PrintfFormat, PrintfWriter

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
PrintfStream(OutputStream pout)
          Creates a PrintfStream, without automatic line flushing, from an existing OutputStream.
PrintfStream(OutputStream pout, boolean autoFlush)
          Creates a PrintfStream from an existing OutputStream.
 
Method Summary
 void printf(PrintfFormat fmt, char x)
          Prints a char in accordance with the supplied PrintfFormat object.
 void printf(PrintfFormat fmt, double x)
          Prints a double in accordance with the supplied PrintfFormat object.
 void printf(PrintfFormat fmt, float x)
          Prints a float in accordance with the supplied PrintfFormat object.
 void printf(PrintfFormat fmt, int x)
          Prints an int in accordance with the supplied PrintfFormat object.
 void printf(PrintfFormat fmt, long x)
          Prints a long in accordance with the supplied PrintfFormat object.
 void printf(PrintfFormat fmt, String x)
          Prints a String in accordance with the supplied PrintfFormat object.
 void printf(String fs, char x)
          Prints a char in accordance with the supplied format string.
 void printf(String fs, double x)
          Prints a double in accordance with the supplied format string.
 void printf(String fs, float x)
          Prints a float in accordance with the supplied format string.
 void printf(String fs, int x)
          Prints an int in accordance with the supplied format string.
 void printf(String fs, long x)
          Prints a long in accordance with the supplied format string.
 void printf(String fs, String x)
          Prints a String in accordance with the supplied format string.
 
Methods inherited from class java.io.PrintStream
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
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintfStream

public PrintfStream(OutputStream pout)
Creates a PrintfStream, without automatic line flushing, from an existing OutputStream.

Parameters:
out - An output stream

PrintfStream

public PrintfStream(OutputStream pout,
                    boolean autoFlush)
Creates a PrintfStream from an existing OutputStream.

Parameters:
out - An output stream
autoFlush - If true, specifies that output flushing will automatically occur when the println() methods are called, a byte array is written, or a new line character or byte is encountered in the output.
Method Detail

printf

public void printf(String fs,
                   double x)
Prints a double in accordance with the supplied format string.

Parameters:
fs - Format string
x - Double to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(String fs,
                   float x)
Prints a float in accordance with the supplied format string.

Parameters:
fs - Format string
x - Float to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(String fs,
                   long x)
Prints a long in accordance with the supplied format string.

Parameters:
fs - Format string
x - Long to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(String fs,
                   int x)
Prints an int in accordance with the supplied format string.

Parameters:
fs - Format string
x - Int to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(String fs,
                   String x)
Prints a String in accordance with the supplied format string.

Parameters:
fs - Format string
x - String to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(String fs,
                   char x)
Prints a char in accordance with the supplied format string.

Parameters:
fs - Format string
x - Char to output
Throws:
IllegalArgumentException - Malformed format string

printf

public void printf(PrintfFormat fmt,
                   double x)
Prints a double in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - Double to output
See Also:
PrintfFormat

printf

public void printf(PrintfFormat fmt,
                   float x)
Prints a float in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - Float to output
See Also:
PrintfFormat

printf

public void printf(PrintfFormat fmt,
                   long x)
Prints a long in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - Long to output
See Also:
PrintfFormat

printf

public void printf(PrintfFormat fmt,
                   int x)
Prints an int in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - Int to output
See Also:
PrintfFormat

printf

public void printf(PrintfFormat fmt,
                   String x)
Prints a String in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - String to output
See Also:
PrintfFormat

printf

public void printf(PrintfFormat fmt,
                   char x)
Prints a char in accordance with the supplied PrintfFormat object.

Parameters:
fmt - Formatting object
x - Char to output
See Also:
PrintfFormat


Copyright © 2013. All Rights Reserved.