Class AtomicFileOutputStream

  • All Implemented Interfaces:
    ContentHashable, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    @NotThreadSafe
    public class AtomicFileOutputStream
    extends java.io.OutputStream
    implements ContentHashable
    A AtomicFileOutputStream writes to a temporary file and renames on close. This ensures that writing to the stream is atomic, i.e., all writes become readable only after a close.
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write 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
      • close

        public void close()
                   throws java.io.IOException
        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
      • getContentHash

        public java.util.Optional<java.lang.String> getContentHash()
                                                            throws java.io.IOException
        Specified by:
        getContentHash in interface ContentHashable
        Returns:
        the content hash of the file written to the UFS if available after the stream has been closed
        Throws:
        java.io.IOException