hudson.util
Class AtomicFileWriter
java.lang.Object
java.io.Writer
hudson.util.AtomicFileWriter
- All Implemented Interfaces:
- Closeable, Flushable, Appendable
public class AtomicFileWriter
- extends Writer
Buffered FileWriter
that uses UTF-8.
The write operation is atomic when used for overwriting;
it either leaves the original file intact, or it completely rewrites it with new contents.
- Author:
- Kohsuke Kawaguchi
Method Summary |
void |
abort()
When the write operation failed, call this method to
leave the original file intact and remove the temporary file. |
void |
close()
|
void |
commit()
|
protected void |
finalize()
|
void |
flush()
|
File |
getTemporaryFile()
Until the data is committed, this file captures
the written content. |
void |
write(char[] cbuf,
int off,
int len)
|
void |
write(int c)
|
void |
write(String str,
int off,
int len)
|
AtomicFileWriter
public AtomicFileWriter(File f)
throws IOException
- Writes with UTF-8 encoding.
- Throws:
IOException
AtomicFileWriter
public AtomicFileWriter(File f,
String encoding)
throws IOException
- Parameters:
encoding
- File encoding to write. If null, platform default encoding is chosen.
- Throws:
IOException
write
public void write(int c)
throws IOException
- Overrides:
write
in class Writer
- Throws:
IOException
write
public void write(String str,
int off,
int len)
throws IOException
- Overrides:
write
in class Writer
- Throws:
IOException
write
public void write(char[] cbuf,
int off,
int len)
throws IOException
- Specified by:
write
in class Writer
- Throws:
IOException
flush
public void flush()
throws IOException
- Specified by:
flush
in interface Flushable
- Specified by:
flush
in class Writer
- Throws:
IOException
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Specified by:
close
in class Writer
- Throws:
IOException
abort
public void abort()
throws IOException
- When the write operation failed, call this method to
leave the original file intact and remove the temporary file.
This method can be safely invoked from the "finally" block, even after
the
commit()
is called, to simplify coding.
- Throws:
IOException
commit
public void commit()
throws IOException
- Throws:
IOException
finalize
protected void finalize()
throws Throwable
- Overrides:
finalize
in class Object
- Throws:
Throwable
getTemporaryFile
public File getTemporaryFile()
- Until the data is committed, this file captures
the written content.
Copyright © 2004-2013. All Rights Reserved.