Class SimpleDataOutput

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

    public class SimpleDataOutput
    extends ByteOutputStream
    implements java.io.DataOutput
    A simple base implementation of DataOutput which wraps a ByteOutput. This implementation maintains an internal buffer.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] buffer
      The internal buffer.
      protected int bufferSize
      The size of the internal buffer.
      private int position
      The position in the buffer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      protected void finish()
      Finish writing to a stream.
      void flush()
      private static java.io.NotActiveException notActiveException()  
      protected void shallowFlush()
      This shallow flush will write the internal buffer out to the ByteOutput, but will not flush it.
      protected void start​(ByteOutput byteOutput)
      Begin writing to a stream.
      void write​(byte[] bytes)
      Write all the bytes from the given array to the stream.
      void write​(byte[] bytes, int off, int len)
      Write some of the bytes from the given array to the stream.
      void write​(int v)
      Writes to the output stream the eight low-order bits of the argument b.
      void writeBoolean​(boolean v)
      void writeByte​(int v)
      void writeBytes​(java.lang.String s)
      void writeChar​(int v)
      void writeChars​(java.lang.String s)
      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.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • bufferSize

        protected final int bufferSize
        The size of the internal buffer.
      • buffer

        protected byte[] buffer
        The internal buffer.
      • position

        private int position
        The position in the buffer.
    • Constructor Detail

      • SimpleDataOutput

        public SimpleDataOutput​(int bufferSize)
        Construct a new instance.
        Parameters:
        bufferSize - the buffer size
      • SimpleDataOutput

        public SimpleDataOutput​(int bufferSize,
                                ByteOutput byteOutput)
        Construct a new instance.
        Parameters:
        bufferSize - the buffer size
        byteOutput - the byte output to wrap
      • SimpleDataOutput

        public SimpleDataOutput​(ByteOutput byteOutput)
        Construct a new instance with a default buffer size.
        Parameters:
        byteOutput - the byte output to wrap
    • Method Detail

      • notActiveException

        private static java.io.NotActiveException notActiveException()
      • write

        public void write​(int v)
                   throws java.io.IOException
        Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.
        Specified by:
        write in interface ByteOutput
        Specified by:
        write in interface java.io.DataOutput
        Overrides:
        write in class ByteOutputStream
        Parameters:
        v - the byte to write
        Throws:
        java.io.IOException - if an error occurs
      • write

        public void write​(byte[] bytes)
                   throws java.io.IOException
        Write all the bytes from the given array to the stream.
        Specified by:
        write in interface ByteOutput
        Specified by:
        write in interface java.io.DataOutput
        Overrides:
        write in class ByteOutputStream
        Parameters:
        bytes - the byte array
        Throws:
        java.io.IOException - if an error occurs
      • write

        public void write​(byte[] bytes,
                          int off,
                          int len)
                   throws java.io.IOException
        Write some of the bytes from the given array to the stream.
        Specified by:
        write in interface ByteOutput
        Specified by:
        write in interface java.io.DataOutput
        Overrides:
        write in class ByteOutputStream
        Parameters:
        bytes - the byte array
        off - the index to start writing from
        len - the number of bytes to write
        Throws:
        java.io.IOException - if an error occurs
      • writeBoolean

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

        public void writeByte​(int v)
                       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
      • writeChar

        public void writeChar​(int v)
                       throws java.io.IOException
        Specified by:
        writeChar 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
      • 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
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class ByteOutputStream
        Throws:
        java.io.IOException
      • shallowFlush

        protected void shallowFlush()
                             throws java.io.IOException
        This shallow flush will write the internal buffer out to the ByteOutput, but will not flush it.
        Throws:
        java.io.IOException - if an I/O error occurs
      • start

        protected void start​(ByteOutput byteOutput)
                      throws java.io.IOException
        Begin writing to a stream.
        Parameters:
        byteOutput - the new stream
        Throws:
        java.io.IOException - if an error occurs
      • finish

        protected void finish()
                       throws java.io.IOException
        Finish writing to a stream. The stream is released. No further writing may be done until the start(ByteOutput) method is again invoked.
        Throws:
        java.io.IOException - if an error occurs
      • 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 ByteOutputStream
        Throws:
        java.io.IOException