org.sadun.util
Class PrefixPrintWriter

java.lang.Object
  extended byjava.io.Writer
      extended byjava.io.PrintWriter
          extended byorg.sadun.util.PrefixPrintWriter

public class PrefixPrintWriter
extends java.io.PrintWriter

A PrintWriter that unconditionally prefixes any new line of output with a given prefix.

The prefix may be a constant string, or computed on each invocation if a PrefixProvider object is given at construction

Version:
1.1
Author:
C. Sadun

Nested Class Summary
static class PrefixPrintWriter.DirectoryPrefixProvider
          A prefix provider to show the current directory as a prefix.
 
Field Summary
static org.sadun.util.PrefixPrintWriter.TimePrefixProvider TIME_PREFIXPROVIDER
          A built-in provider which prefixes the output with time information
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
PrefixPrintWriter(java.io.OutputStream os, PrefixProvider pp)
          Build a PrefixPrintWriter which wraps the given output stream, and use the given PrefixProvider to determine the prefix.
PrefixPrintWriter(java.io.OutputStream os, java.lang.String prefix)
          Build a PrefixPrintWriter which wraps the given output stream, and prefixes lines with the given constant string
PrefixPrintWriter(java.io.Writer w, PrefixProvider pp)
          Build a PrefixPrintWriter which wraps the given writer, and use the given PrefixProvider to determine the prefix.
PrefixPrintWriter(java.io.Writer w, java.lang.String prefix)
          Build a PrefixPrintWriter which wraps the given writer, and prefixes lines with the given constant string
 
Method Summary
static void main(java.lang.String[] args)
           
 void println()
          Terminate the current line by writing the line separator string.
 void write(char[] buf, int off, int len)
          Write a portion of character array, of given length from a given offset
 void write(int c)
          Write a character
 void write(java.lang.String s, int off, int len)
          Write a substring of a string, of given length from a given offset
 
Methods inherited from class java.io.PrintWriter
checkError, close, flush, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, setError, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_PREFIXPROVIDER

public static final org.sadun.util.PrefixPrintWriter.TimePrefixProvider TIME_PREFIXPROVIDER
A built-in provider which prefixes the output with time information

Constructor Detail

PrefixPrintWriter

public PrefixPrintWriter(java.io.Writer w,
                         PrefixProvider pp)
Build a PrefixPrintWriter which wraps the given writer, and use the given PrefixProvider to determine the prefix.

Parameters:
w - the writer to wrap on
pp - the PrefixProvider providing the prefix for each line

PrefixPrintWriter

public PrefixPrintWriter(java.io.Writer w,
                         java.lang.String prefix)
Build a PrefixPrintWriter which wraps the given writer, and prefixes lines with the given constant string

Parameters:
w - the writer to wrap on
prefix - the prefix for each line

PrefixPrintWriter

public PrefixPrintWriter(java.io.OutputStream os,
                         PrefixProvider pp)
Build a PrefixPrintWriter which wraps the given output stream, and use the given PrefixProvider to determine the prefix.

Parameters:
os - the output stream to wrap on
pp - the PrefixProvider providing the prefix for each line

PrefixPrintWriter

public PrefixPrintWriter(java.io.OutputStream os,
                         java.lang.String prefix)
Build a PrefixPrintWriter which wraps the given output stream, and prefixes lines with the given constant string

Parameters:
os - the output stream to wrap on
prefix - the prefix for each line
Method Detail

write

public void write(int c)
Write a character


write

public void write(java.lang.String s,
                  int off,
                  int len)
Write a substring of a string, of given length from a given offset


write

public void write(char[] buf,
                  int off,
                  int len)
Write a portion of character array, of given length from a given offset


println

public void println()
Terminate the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception