org.apache.commons.io.output
Class LockableFileWriter

java.lang.Object
  extended by java.io.Writer
      extended by org.apache.commons.io.output.LockableFileWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

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 140517 2004-02-23 04:40:29Z bayard $
Author:
Scott Sanders, Michael Salmon, Jon S. Stevens, Daniel Rall

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
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()
           
 void flush()
           
 void write(char[] cbuf, int off, int len)
           
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockableFileWriter

public LockableFileWriter(String fileName)
                   throws IOException
Constructs a LockableFileWriter. If the file exists, it is overwritten.

Parameters:
fileName - file to write to
Throws:
IOException - in case of an I/O error

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).
Throws:
IOException - in case of an I/O error

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.
Throws:
IOException - in case of an I/O error

LockableFileWriter

public LockableFileWriter(File file)
                   throws IOException
Constructs a LockableFileWriter. If the file exists, it is overwritten.

Parameters:
file - file to write to
Throws:
IOException - in case of an I/O error

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).
Throws:
IOException - in case of an I/O error

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.
Throws:
IOException - in case of an I/O error
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException
See Also:
Writer.close()

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException
See Also:
Writer.write(char[], int, int)

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException
See Also:
Writer.flush()


Copyright © 2002-2005 The Apache Software Foundation. All Rights Reserved.