public class DatedFileOutputStream
extends java.io.OutputStream
Same as DatedFileWriter, but used for streams. This one is required for redirecting System.out since that is a stream, not a writer.
DatedFileWriter| Modifier and Type | Field and Description |
|---|---|
protected boolean |
append
True if we are to open files in append mode.
|
protected java.text.SimpleDateFormat |
dateFormat
The SimpleDateFormat makes it easy to produce the pattern string, the
actual name pattern is passed right to it.
|
protected java.io.FileOutputStream |
fos
Null if not open, else used to access the underlying file.
|
protected java.lang.String |
lastFileName
The name of the file we last wrote to or null if we haven't written to
one yet.
|
protected java.lang.String |
namePattern
The original name pattern passed in.
|
protected java.io.File |
parentDir
The parent directory to create files in.
|
| Constructor and Description |
|---|
DatedFileOutputStream(java.lang.String namePattern)
Create a new DatedFileOutputStream using the current directory and the
given file name pattern.
|
DatedFileOutputStream(java.lang.String parentPath,
java.lang.String namePattern,
boolean append)
Create a new DatedFileOutputStream using the given parent directory and
the given file name pattern.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the stream.
|
void |
flush()
Flush the stream.
|
void |
write(byte[] buf,
int off,
int len)
Write the given sub-array to the file.
|
void |
write(int b)
Write the given int to the file.
|
protected java.lang.String lastFileName
protected java.lang.String namePattern
protected java.text.SimpleDateFormat dateFormat
SimpleDateFormatprotected java.io.FileOutputStream fos
Note: I've noticed that if a file is deleted or renamed while open no exception is thrown at least on Solaris 2.6. Perhaps this should periodically (writes > 30,000 millis apart?) close and reopen the FileWriter. And maybe a OS person could explain this strange behavior and how to avoid it!
protected boolean append
protected java.io.File parentDir
public DatedFileOutputStream(java.lang.String parentPath,
java.lang.String namePattern,
boolean append)
throws java.io.IOException
parentPath - The parent directory to create files in. If null, use
current directory.namePattern - A String formatted for direct use by SimpleDateFormat
to make the file name.append - Set to true to append to a pre-existing log, false to
overwrite.java.io.IOExceptionpublic DatedFileOutputStream(java.lang.String namePattern)
throws java.io.IOException
Use the current directory, appending to the file if it exists.
namePattern - A String formatted for direct use by SimpleDateFormat
to make the file name.java.io.IOExceptionpublic void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - the int to write.java.io.IOExceptionpublic void write(byte[] buf,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreambuf - the array from which to write bytes.off - The offset into the char array to begin writing from.len - The number of characters to write.java.io.IOException - If an error occurs during the write.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionCopyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.