Class 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
    • 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)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BackingOutputStream

        public BackingOutputStream​(java.io.File file)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • BackingOutputStream

        public BackingOutputStream​(java.lang.String file)
                            throws java.io.IOException
        Throws:
        java.io.IOException
    • 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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException