|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
common.io.AtomicOutputStream
An "atomic" output stream. It is "atomic" in the sense that the target file won't be overwritten until "close()" is called, at which point a rename is done. A point of note that for this stream to actually be atomic, "rename" needs to be atomic, such as in POSIX systems. Windows, for example, doesn't have this property, so this stream tries to do the next best thing (delete the original, then rename).
This stream works a little bit differently than other streams, in the
sense that it has a second close method called rollback()
. This
method just discards the temporary file used to write the data and leaves
the target file untouched. The only way to overwrite the target file is
to call close()
. If the instance is left for garbage collection,
rollback()
will be called during finalization, instead of
close().
Constructor Summary | |
AtomicOutputStream(java.io.File path)
Creates a new atomic stream. |
|
AtomicOutputStream(java.lang.String path)
Creates a new atomic stream. |
Method Summary | |
void |
close()
Closes the temporary stream and renames the temp file to the target file. |
protected void |
finalize()
For the forgetful. |
void |
flush()
|
void |
rollback()
Removes the temporary file without overwriting the target. |
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AtomicOutputStream(java.lang.String path) throws java.io.IOException
AtomicOutputStream(File)
public AtomicOutputStream(java.io.File path) throws java.io.IOException
path
, otherwise this will throw
an IOException.
path
- The path of the target file.
java.io.IOException
- If the temp file cannot be created.Method Detail |
public void close() throws java.io.IOException
java.io.IOException
- If there's a problem closing the temp stream, or
renaming the temp file to the target file.public void flush() throws java.io.IOException
java.io.IOException
public void write(byte[] b) throws java.io.IOException
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
public void write(int b) throws java.io.IOException
java.io.IOException
public void rollback()
protected void finalize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |