Class SafeBufferedOutputStream

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

    public class SafeBufferedOutputStream
    extends java.io.BufferedOutputStream
    A BufferedOutputStream that throws an error if the final flush fails on close.

    Java's BufferedOutputStream swallows errors that occur when the output stream tries to write the final bytes to the output during close. This may result in corrupted files without notice.

    • Field Summary

      • Fields inherited from class java.io.BufferedOutputStream

        buf, count
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      • Methods inherited from class java.io.BufferedOutputStream

        flush, write, write
      • Methods inherited from class java.io.FilterOutputStream

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

      • SafeBufferedOutputStream

        public SafeBufferedOutputStream​(java.io.OutputStream out)
        Parameters:
        out - underlying output stream
        See Also:
        BufferedOutputStream(OutputStream)
      • SafeBufferedOutputStream

        public SafeBufferedOutputStream​(java.io.OutputStream out,
                                        int size)
        Parameters:
        out - underlying output stream
        size - buffer size
        See Also:
        BufferedOutputStream(OutputStream, int)
    • Method Detail

      • 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.FilterOutputStream
        Throws:
        java.io.IOException