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.OutputStream
An 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 void
close()
Close the temporary file and copy it over the real file.void
flush()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Close 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
-