Class FastBufferedOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable
    Direct Known Subclasses:
    FastBufferedOutputStream

    public class FastBufferedOutputStream
    extends java.io.FilterOutputStream
    A simple, non-synchronized buffered output stream for improved performance.

    The FastBufferedOutputStream class provides a buffered output stream implementation that improves performance by reducing the number of calls to the underlying output stream. Unlike the standard BufferedOutputStream, this implementation does not include synchronization, making it faster but not thread-safe.

    This class is particularly useful in single-threaded contexts where the overhead of synchronization is unnecessary. It uses a fixed-size buffer (8192 bytes) to collect written data before flushing it to the underlying output stream.

    Key features include:

    • No synchronization overhead for improved performance
    • Fixed-size buffer to reduce system calls
    • Compatible with the standard OutputStream API

    Note that this class is not thread-safe and should not be used in multi-threaded contexts without external synchronization.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] buf  
      protected int count  
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.FilterOutputStream

        close, 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
    • Field Detail

      • buf

        protected final byte[] buf
      • count

        protected int count
    • Constructor Detail

      • FastBufferedOutputStream

        public FastBufferedOutputStream​(java.io.OutputStream out)
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        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.FilterOutputStream
        Throws:
        java.io.IOException