Class DataBufferedOutputStream

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

    public class DataBufferedOutputStream
    extends java.io.BufferedOutputStream
    implements java.io.DataOutput
    BufferedOutputStream subclass implementing the DataOutput interface. This is considerably faster than simply layering a DataOutputStream on top of a BufferedOutputStream.

    The implementation was largely copied from nom.tam.util.BufferedDataOutputStream.

    Author:
    Mark Taylor, Tom McGlynn
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_BUFFER_SIZE
      Default buffer size 8192, same as java.io.BufferedOutputStream.
      • Fields inherited from class java.io.BufferedOutputStream

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

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      DataBufferedOutputStream​(java.io.OutputStream out)
      Constructs a stream with a default buffer size.
      DataBufferedOutputStream​(java.io.OutputStream out, int size)
      Constructs a stream with a given buffer size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void checkBuf​(int need)
      Try to ensure there is a given number of bytes in the buffer.
      void writeBoolean​(boolean b)  
      void writeByte​(int b)  
      void writeBytes​(java.lang.String s)  
      void writeChar​(int v)  
      void writeChars​(java.lang.String s)  
      void writeCharUTF8​(char c)
      Writes a single character in UTF8 format.
      void writeDouble​(double v)  
      void writeFloat​(float v)  
      void writeInt​(int v)  
      void writeLong​(long v)  
      void writeShort​(int v)  
      void writeUTF​(java.lang.String s)  
      • Methods inherited from class java.io.BufferedOutputStream

        flush, write, write
      • 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
      • Methods inherited from interface java.io.DataOutput

        write, write, write
    • Field Detail

      • DEFAULT_BUFFER_SIZE

        public static final int DEFAULT_BUFFER_SIZE
        Default buffer size 8192, same as java.io.BufferedOutputStream.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DataBufferedOutputStream

        public DataBufferedOutputStream​(java.io.OutputStream out)
        Constructs a stream with a default buffer size. The default buffer size is currently 8k.
        Parameters:
        out - base output stream
      • DataBufferedOutputStream

        public DataBufferedOutputStream​(java.io.OutputStream out,
                                        int size)
        Constructs a stream with a given buffer size.
        Parameters:
        out - base output stream
        size - buffer size in bytes, must be >=8
    • Method Detail

      • writeBoolean

        public void writeBoolean​(boolean b)
                          throws java.io.IOException
        Specified by:
        writeBoolean in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeByte

        public void writeByte​(int b)
                       throws java.io.IOException
        Specified by:
        writeByte in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeShort

        public void writeShort​(int v)
                        throws java.io.IOException
        Specified by:
        writeShort in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeInt

        public void writeInt​(int v)
                      throws java.io.IOException
        Specified by:
        writeInt in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeLong

        public void writeLong​(long v)
                       throws java.io.IOException
        Specified by:
        writeLong in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChar

        public void writeChar​(int v)
                       throws java.io.IOException
        Specified by:
        writeChar in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeFloat

        public void writeFloat​(float v)
                        throws java.io.IOException
        Specified by:
        writeFloat in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeDouble

        public void writeDouble​(double v)
                         throws java.io.IOException
        Specified by:
        writeDouble in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeBytes

        public void writeBytes​(java.lang.String s)
                        throws java.io.IOException
        Specified by:
        writeBytes in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChars

        public void writeChars​(java.lang.String s)
                        throws java.io.IOException
        Specified by:
        writeChars in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeUTF

        public void writeUTF​(java.lang.String s)
                      throws java.io.IOException
        Specified by:
        writeUTF in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeCharUTF8

        public void writeCharUTF8​(char c)
                           throws java.io.IOException
        Writes a single character in UTF8 format.
        Parameters:
        c - character to write
        Throws:
        java.io.IOException
      • checkBuf

        protected void checkBuf​(int need)
                         throws java.io.IOException
        Try to ensure there is a given number of bytes in the buffer. If it's nearly full, it will be flushed ready for more data. This call does not guarantee that the requested number of bytes are free in the buffer; if the request is more than the buffer length, the buffer is simply flushed.
        Parameters:
        need - number of bytes required
        Throws:
        java.io.IOException