

Public Member Functions | |
| ErrorLogFile (int timeout, String prefix, String suffix, String folder, boolean deleteOnExit, boolean retryOnError) | |
| synchronized void | run () |
| synchronized void | append (String str) throws IOException |
| synchronized void | copy (OutputStream file) throws FileNotFoundException, IOException |
| synchronized void | clear () |
| synchronized void | close () |
| synchronized String | getFileName () |
Protected Member Functions | |
| void | finalize () throws Throwable |
Private Member Functions | |
| void | initTmpFile () throws IOException |
Private Attributes | |
| Timer | timer = new Timer("ErrorLogFile",true) |
| final int | timeout |
| long | lastWriteTime = -1 |
| final boolean | deleteOnExit |
| final boolean | retryOnError |
| final String | prefix |
| final String | suffix |
| final String | folder |
| String | fileName |
| FileOutputStream | outFile = null |
| boolean | fileError = false |
| boolean | closed = false |
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:
The used file is identified by its name;
| alma::acs::logging::dialogs::error::ErrorLogFile::ErrorLogFile | ( | int | timeout, | |
| String | prefix, | |||
| String | suffix, | |||
| String | folder, | |||
| boolean | deleteOnExit, | |||
| boolean | retryOnError | |||
| ) | [inline] |
Constructor.
| timeout | The number of seconds before closing the file | |
| prefix | The prefix of the temporary file | |
| suffix | The suffix of the temporary file | |
| folder | The name of the folder where the new file must be created; if it is null or empty, then the current folder is used | |
| deleteOnExit | if true the file s deleted when the application exits | |
| retryOnError | if true tries to open the file even if a previous attempt failed |
References timer.
| synchronized void alma::acs::logging::dialogs::error::ErrorLogFile::append | ( | String | str | ) | throws IOException [inline] |
Append a string to the temporary file.
| str | The string to append in the file |
References closed, fileError, fileName, initTmpFile(), lastWriteTime, outFile, and retryOnError.
Referenced by alma::acs::logging::dialogs::error::ErrorLogDialog::appendText(), alma::acs::jlog::test::ErrorLogFileTest::testAppend(), alma::acs::jlog::test::ErrorLogFileTest::testAppendTimeout(), alma::acs::jlog::test::ErrorLogFileTest::testClear(), and alma::acs::jlog::test::ErrorLogFileTest::testCopy().
| synchronized void alma::acs::logging::dialogs::error::ErrorLogFile::clear | ( | ) | [inline] |
Close the file(s) freeing all the resources
This is the last method executed by this class
References fileError, fileName, lastWriteTime, and outFile.
Referenced by alma::acs::logging::dialogs::error::ErrorLogDialog::clearAll(), close(), and alma::acs::jlog::test::ErrorLogFileTest::testClear().
| synchronized void alma::acs::logging::dialogs::error::ErrorLogFile::close | ( | ) | [inline] |
Close clear the file and stop the timer.
This is the last method to execute.
References clear(), closed, and timer.
Referenced by alma::acs::logging::dialogs::error::ErrorLogDialog::dispose(), and finalize().
| synchronized void alma::acs::logging::dialogs::error::ErrorLogFile::copy | ( | OutputStream | file | ) | throws FileNotFoundException, IOException [inline] |
Copy the file in the passed output stream
| file | The stream to copy the content of the file into |
References fileName, and lastWriteTime.
Referenced by alma::acs::logging::dialogs::error::ErrorLogDialog::saveAllLog(), and alma::acs::jlog::test::ErrorLogFileTest::testCopy().
| void alma::acs::logging::dialogs::error::ErrorLogFile::finalize | ( | ) | throws Throwable [inline, protected] |
Flush and close the file when the object is destroyed by the GC
References close().
| synchronized String alma::acs::logging::dialogs::error::ErrorLogFile::getFileName | ( | ) | [inline] |
References fileName.
Referenced by alma::acs::jlog::test::ErrorLogFileTest::testAppend(), alma::acs::jlog::test::ErrorLogFileTest::testAppendTimeout(), and alma::acs::jlog::test::ErrorLogFileTest::testClear().
| void alma::acs::logging::dialogs::error::ErrorLogFile::initTmpFile | ( | ) | throws IOException [inline, private] |
| synchronized void alma::acs::logging::dialogs::error::ErrorLogFile::run | ( | ) | [inline] |
The method executed by the Timer.
References fileError, lastWriteTime, outFile, and timeout.
boolean alma::acs::logging::dialogs::error::ErrorLogFile::closed = false [private] |
final boolean alma::acs::logging::dialogs::error::ErrorLogFile::deleteOnExit [private] |
If true the file will be deleted when the application terminates.
Referenced by initTmpFile().
boolean alma::acs::logging::dialogs::error::ErrorLogFile::fileError = false [private] |
String alma::acs::logging::dialogs::error::ErrorLogFile::fileName [private] |
The name of the file for I/O.
Referenced by append(), clear(), copy(), getFileName(), and initTmpFile().
final String alma::acs::logging::dialogs::error::ErrorLogFile::folder [private] |
The folder where the temporary file must be written
Referenced by initTmpFile().
long alma::acs::logging::dialogs::error::ErrorLogFile::lastWriteTime = -1 [private] |
FileOutputStream alma::acs::logging::dialogs::error::ErrorLogFile::outFile = null [private] |
final String alma::acs::logging::dialogs::error::ErrorLogFile::prefix [private] |
The prefix of the temporary file
Referenced by initTmpFile().
final boolean alma::acs::logging::dialogs::error::ErrorLogFile::retryOnError [private] |
If true the application tries to perform I/O in the file even if a previous attempt resulted in an error.
Referenced by append().
final String alma::acs::logging::dialogs::error::ErrorLogFile::suffix [private] |
The suffix of the temporary file
Referenced by initTmpFile().
final int alma::acs::logging::dialogs::error::ErrorLogFile::timeout [private] |
The number of seconds before closing the file
Referenced by run().
Timer alma::acs::logging::dialogs::error::ErrorLogFile::timer = new Timer("ErrorLogFile",true) [private] |
The timer to check the time before two flush.
Referenced by close(), and ErrorLogFile().
1.6.2