org.apache.commons.io.output
public class LockableFileWriter extends Writer
This class provides a simple alternative to FileWriter
that will use a lock file to prevent duplicate writes.
By default, the file will be overwritten, but this may be changed to append.
The lock directory may be specified, but defaults to the system property
java.io.tmpdir
.
The encoding may also be specified, and defaults to the platform default.
Version: $Id: LockableFileWriter.java 610010 2008-01-08 14:50:59Z niallp $
Field Summary | |
---|---|
File | lockFile The lock file. |
static String | LCK The extension for the lock file. |
Writer | out The writer to decorate. |
Constructor Summary | |
---|---|
LockableFileWriter(String fileName)
Constructs a LockableFileWriter.
| |
LockableFileWriter(String fileName, boolean append)
Constructs a LockableFileWriter.
| |
LockableFileWriter(String fileName, boolean append, String lockDir)
Constructs a LockableFileWriter.
| |
LockableFileWriter(File file)
Constructs a LockableFileWriter.
| |
LockableFileWriter(File file, boolean append)
Constructs a LockableFileWriter.
| |
LockableFileWriter(File file, boolean append, String lockDir)
Constructs a LockableFileWriter.
| |
LockableFileWriter(File file, String encoding)
Constructs a LockableFileWriter with a file encoding.
| |
LockableFileWriter(File file, String encoding, boolean append, String lockDir)
Constructs a LockableFileWriter with a file encoding.
|
Method Summary | |
---|---|
void | close()
Closes the file writer.
|
void | createLock()
Creates the lock file.
|
void | flush()
Flush the stream. |
Writer | initWriter(File file, String encoding, boolean append)
Initialise the wrapped file writer.
|
void | testLockDir(File lockDir)
Tests that we can write to the lock directory.
|
void | write(int idx)
Write a character. |
void | write(char[] chr)
Write the characters from an array. |
void | write(char[] chr, int st, int end)
Write the specified characters from an array. |
void | write(String str)
Write the characters from a string. |
void | write(String str, int st, int end)
Write the specified characters from a string. |
Parameters: fileName the file to write to, not null
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: fileName file to write to, not null append true if content should be appended, false to overwrite
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: fileName the file to write to, not null append true if content should be appended, false to overwrite lockDir the directory in which the lock file should be held
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: file the file to write to, not null
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: file the file to write to, not null append true if content should be appended, false to overwrite
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: file the file to write to, not null append true if content should be appended, false to overwrite lockDir the directory in which the lock file should be held
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: file the file to write to, not null encoding the encoding to use, null means platform default
Throws: NullPointerException if the file is null IOException in case of an I/O error
Parameters: file the file to write to, not null encoding the encoding to use, null means platform default append true if content should be appended, false to overwrite lockDir the directory in which the lock file should be held
Throws: NullPointerException if the file is null IOException in case of an I/O error
Throws: IOException if an I/O error occurs
Throws: IOException if we cannot create the file
Throws: IOException if an I/O error occurs
Parameters: file the file to be accessed encoding the encoding to use append true to append
Returns: The initialised writer
Throws: IOException if an error occurs
Parameters: lockDir the File representing the lock directory
Throws: IOException if we cannot write to the lock directory IOException if we cannot find the lock file
Parameters: idx the character to write
Throws: IOException if an I/O error occurs
Parameters: chr the characters to write
Throws: IOException if an I/O error occurs
Parameters: chr the characters to write st The start offset end The number of characters to write
Throws: IOException if an I/O error occurs
Parameters: str the string to write
Throws: IOException if an I/O error occurs
Parameters: str the string to write st The start offset end The number of characters to write
Throws: IOException if an I/O error occurs