1-Wire Weather Service for Java -- Server API

wxservice
Class DailyPrintStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.PrintStream
              extended by wxservice.DailyPrintStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class DailyPrintStream
extends java.io.PrintStream

Print stream for managing daily log files. The following example shows how to redirect System.out and System.err to use DailyPrintStream:

 System.setOut(DailyPrintStream.getInstance());
 System.setErr(DailyPrintStream.getInstance());
 
The file name format is "log\yyyy-MM-dd.txt" in the current directory. The log directory must exist.

Author:
Copyright © 2005 - 2008 Karl Uppiano.

Field Summary
private static java.text.Format DATE_FORMAT
          Formatter for date-time string.
private static java.io.PrintStream m_instance
          Singleton instance.
private  long m_time
          Time of last date check.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
private DailyPrintStream()
          Creates a new instance of PrintStream
 
Method Summary
private  void checkDate()
          Checks the date and creates a new file output stream if necessary.
static java.io.PrintStream getInstance()
          Accessor for the single instance of DailyPrintStream.
 void write(byte[] buf, int off, int len)
          This method overrides the standard 3-argument write method.
 void write(int b)
          This method overrides the standard 1-argument write method.
 
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
 
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
 

Field Detail

DATE_FORMAT

private static final java.text.Format DATE_FORMAT
Formatter for date-time string.


m_instance

private static java.io.PrintStream m_instance
Singleton instance.


m_time

private long m_time
Time of last date check.

Constructor Detail

DailyPrintStream

private DailyPrintStream()
                  throws java.io.IOException
Creates a new instance of PrintStream

Throws:
java.io.IOException - if file creation fails.
Method Detail

getInstance

public static java.io.PrintStream getInstance()
                                       throws java.io.IOException
Accessor for the single instance of DailyPrintStream.

Returns:
the single instance of DailyPrintStream. Creates a new instance on the first invocation of this method.
Throws:
java.io.IOException - if creation fails.

write

public void write(byte[] buf,
                  int off,
                  int len)
This method overrides the standard 3-argument write method. It has the same behavior except that it checks the date and creates a new file if the date has changed since the last write.

Overrides:
write in class java.io.PrintStream
Parameters:
buf - the byte array to print.
off - starting point in the buffer.
len - number of bytes to write.

write

public void write(int b)
This method overrides the standard 1-argument write method. It has the same behavior except that it checks the date and creates a new file if the date has changed since the last write. This would be a very expensive way to write buffered text. Only re-checks the date if more than 100 milliseconds elapse between subsequent calls.

Overrides:
write in class java.io.PrintStream
Parameters:
b - the byte to write.

checkDate

private void checkDate()
                throws java.io.IOException
Checks the date and creates a new file output stream if necessary.

Throws:
java.io.IOException - if file creation fails.

Copyright © 2005-2008 Karl Uppiano