Class ByteArrayDataOutputStream

  • All Implemented Interfaces:
    java.io.DataOutput

    public class ByteArrayDataOutputStream
    extends java.lang.Object
    implements java.io.DataOutput
    Implements DataOutput over a byte[] buffer. The byte[] buffer expands when needed; however, it doesn't double but only expands minimally, to accommodate the additional data. It is therefore recommended to always size the buffer to the actual number of bytes needed. This class is not thread safe.
    Since:
    3.5
    Author:
    Bela Ban
    • Field Detail

      • buf

        protected byte[] buf
      • pos

        protected int pos
      • grow_exponentially

        protected boolean grow_exponentially
    • Constructor Detail

      • ByteArrayDataOutputStream

        public ByteArrayDataOutputStream()
      • ByteArrayDataOutputStream

        public ByteArrayDataOutputStream​(int capacity)
      • ByteArrayDataOutputStream

        public ByteArrayDataOutputStream​(int capacity,
                                         boolean grow_exponentially)
    • Method Detail

      • position

        public int position()
      • buffer

        public byte[] buffer()
      • getBuffer

        public Buffer getBuffer()
      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer()
      • growExponentially

        public boolean growExponentially()
      • write

        public void write​(int b)
        Specified by:
        write in interface java.io.DataOutput
      • write

        public void write​(byte[] b)
        Specified by:
        write in interface java.io.DataOutput
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
        Specified by:
        write in interface java.io.DataOutput
      • writeBoolean

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

        public void writeByte​(int v)
        Specified by:
        writeByte in interface java.io.DataOutput
      • writeShort

        public void writeShort​(int v)
        Specified by:
        writeShort in interface java.io.DataOutput
      • writeChar

        public void writeChar​(int v)
        Specified by:
        writeChar in interface java.io.DataOutput
      • writeInt

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

        public void writeLong​(long v)
        Specified by:
        writeLong in interface java.io.DataOutput
      • writeFloat

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

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

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

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

        public void writeUTF​(java.lang.String str)
        Specified by:
        writeUTF in interface java.io.DataOutput
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • checkBounds

        protected int checkBounds​(int pos)
      • ensureCapacity

        protected void ensureCapacity​(int bytes)
        Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentially