Package ca.cgjennings.io
Class BackingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- ca.cgjennings.io.BackingOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class BackingOutputStream extends java.io.OutputStreamAn output stream that writes to a file, but it writes initially to a file other than the one requested. If the process succeeds and the file is closed without any exceptions, then the temporary file is overwritten with the new content. If an exception is thrown while the file is written or the is never closed, then the original file is not modified.WARNING: NOT YET IMPLEMENTED
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description BackingOutputStream(java.io.File file)BackingOutputStream(java.lang.String file)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the temporary file and copy it over the real file.voidflush()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionClose the temporary file and copy it over the real file. If any exceptions have been thrown from this instance while this file was written to, then an exception will be thrown. If the temporary file throws an exception when closed, an exception will be thrown. Otherwise, the following actions occur: (1) If the target file exists, it is renamed to a temporary file name. (2) The temporary file is renamed to the target file. (3) The original, now renamed, file is deleted. If the deletion fails, another attempt is made when the VM exits.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
-