public class ErrorLogFile
extends java.util.TimerTask
ErrorLogFile encapsulates a file adding methods to close
the file when it has not been since used for long time.
In case of error while writing or creating the temporary file,
the behavior depends on the value of retryOnError.
If it is true.
The purpose of this class is to avoid having a file open when no I/O is performed for a long time. This is achieved:
| Constructor and Description |
|---|
ErrorLogFile(int timeout,
java.lang.String prefix,
java.lang.String suffix,
java.lang.String folder,
boolean deleteOnExit,
boolean retryOnError)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(java.lang.String str)
Append a string to the temporary file.
|
void |
clear()
Close the file(s) freeing all the resources
|
void |
close()
Close clear the file and stop the timer.
|
void |
copy(java.io.OutputStream file)
Copy the file in the passed output stream
|
protected void |
finalize()
Flush and close the file when the object is destroyed by the GC
|
java.lang.String |
getFileName() |
void |
run()
The method executed by the
Timer. |
public ErrorLogFile(int timeout,
java.lang.String prefix,
java.lang.String suffix,
java.lang.String folder,
boolean deleteOnExit,
boolean retryOnError)
timeout - The number of seconds before closing the fileprefix - The prefix of the temporary filesuffix - The suffix of the temporary filefolder - The name of the folder where the new file must be created;
if it is null or empty, then the current
folder is useddeleteOnExit - if true the file s deleted when the
application exitsretryOnError - if true tries to open the file even if
a previous attempt failedpublic void run()
Timer.run in interface java.lang.Runnablerun in class java.util.TimerTaskTimer}public void append(java.lang.String str)
throws java.io.IOException
str - The string to append in the filejava.io.IOExceptionpublic void copy(java.io.OutputStream file)
throws java.io.FileNotFoundException,
java.io.IOException
file - The stream to copy the content of the file intojava.io.FileNotFoundExceptionjava.io.IOExceptionpublic void clear()
This is the last method executed by this class
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic void close()
This is the last method to execute.
public java.lang.String getFileName()