org.apache.commons.io.output

Class LockableFileWriter


public class LockableFileWriter
extends Writer

FileWriter that will create and honor lock files to allow simple cross thread file lock handling. If Writer attributes are unspecified, the default behavior is to overwrite (rather than to append), and to use the value of the system property java.io.tmpdir for the lock file directory.
Version:
$Id: LockableFileWriter.java,v 1.7 2004/02/23 04:40:29 bayard Exp $
Authors:
Scott Sanders
Michael Salmon
Jon S. Stevens
Daniel Rall

Field Summary

private static String
LCK
private boolean
append
private File
lockFile
private FileWriter
writer

Constructor Summary

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(String fileName)
Constructs a LockableFileWriter.
LockableFileWriter(String fileName, boolean append)
Constructs a LockableFileWriter.
LockableFileWriter(String fileName, boolean append, String lockDir)
Constructs a LockableFileWriter.

Method Summary

void
close()
private void
createLock()
void
flush()
private void
testLockDir(File lockDir)
void
write(char[] cbuf, int off, int len)

Field Details

LCK

private static final String LCK

append

private boolean append

lockFile

private File lockFile

writer

private FileWriter writer

Constructor Details

LockableFileWriter

public LockableFileWriter(File file)
            throws IOException
Constructs a LockableFileWriter. If the file exists, it is overwritten.
Parameters:
file - file to write to

LockableFileWriter

public LockableFileWriter(File file,
                          boolean append)
            throws IOException
Constructs a LockableFileWriter.
Parameters:
file - file to write to
append - true if content should be appended (default is to overwrite).

LockableFileWriter

public LockableFileWriter(File file,
                          boolean append,
                          String lockDir)
            throws IOException
Constructs a LockableFileWriter.
Parameters:
file - file to write to
append - true if content should be appended (default is to overwrite).
lockDir - Specifies the directory in which the lock file should be held.

LockableFileWriter

public LockableFileWriter(String fileName)
            throws IOException
Constructs a LockableFileWriter. If the file exists, it is overwritten.
Parameters:
fileName - file to write to

LockableFileWriter

public LockableFileWriter(String fileName,
                          boolean append)
            throws IOException
Constructs a LockableFileWriter.
Parameters:
fileName - file to write to
append - true if content should be appended (default is to overwrite).

LockableFileWriter

public LockableFileWriter(String fileName,
                          boolean append,
                          String lockDir)
            throws IOException
Constructs a LockableFileWriter.
Parameters:
fileName - file to write to
append - true if content should be appended (default is to overwrite).
lockDir - Specifies the directory in which the lock file should be held.

Method Details

close

public void close()
            throws IOException
See Also:
java.io.Writer.close()

createLock

private void createLock()
            throws IOException

flush

public void flush()
            throws IOException
See Also:
java.io.Writer.flush()

testLockDir

private void testLockDir(File lockDir)
            throws IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
            throws IOException
See Also:
java.io.Writer.write(char[], int, int)