Class B2FlushAndSyncFileOnCloseOutputStream

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

    public class B2FlushAndSyncFileOnCloseOutputStream
    extends java.io.OutputStream
    Wrap your FileOutputStreams with a B2FlushAndSyncFileOnCloseOutputStream to ensure that your files are always sync'd before being closed. See http://www.pointsoftware.ch/en/4-ext4-vs-ext3-filesystem-and-why-delayed-allocation-is-bad/
    • Method Detail

      • 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
      • 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
      • 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
      • write

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

        public static B2FlushAndSyncFileOnCloseOutputStream create​(java.io.FileOutputStream out)
        Parameters:
        out - the stream to wrap
        Returns:
        a new stream which will carefully finish the file on disk when it's closed.
      • create

        public static B2FlushAndSyncFileOnCloseOutputStream create​(java.io.File outputFile)
                                                            throws java.io.FileNotFoundException
        Parameters:
        outputFile - the file to write to. will be wrapped by a new FileOutputStream.
        Returns:
        a new stream which will carefully finish the file on disk when it's closed.
        Throws:
        java.io.FileNotFoundException