Class CachedOutputStream

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

    public class CachedOutputStream
    extends java.io.BufferedOutputStream
    CachedOutputStream buffers the stream while ignoring flushing. The content is flushed only upon close, so REMEMBER TO CLOSE IT. The purpose is to work around networked file systems which tend to flush too often and result in unbearably poor performance. Example: Microsoft DFS takes ~45s to save 65K xml document.
    Author:
    marius
    • 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()  
      void flush()  
      • Methods inherited from class java.io.BufferedOutputStream

        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

      • CachedOutputStream

        public CachedOutputStream​(java.io.OutputStream out)
      • CachedOutputStream

        public CachedOutputStream​(java.io.OutputStream out,
                                  int size)
      • CachedOutputStream

        public CachedOutputStream​(java.io.File file)
                           throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • CachedOutputStream

        public CachedOutputStream​(java.io.File file,
                                  int size)
                           throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.BufferedOutputStream
      • 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