Class ByteArrayDataOutputStream

  • All Implemented Interfaces:
    java.io.DataOutput

    public class ByteArrayDataOutputStream
    extends BaseDataOutputStream
    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
      • 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

      • buffer

        public byte[] buffer()
      • byteBuffer

        public java.nio.ByteBuffer byteBuffer()
      • capacity

        public int capacity()
      • growExponentially

        public boolean growExponentially()
      • writeChar

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

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

        public void writeLong​(long v)
        Specified by:
        writeLong in interface java.io.DataOutput
        Overrides:
        writeLong in class BaseDataOutputStream
      • writeShort

        public void writeShort​(int v)
        Specified by:
        writeShort in interface java.io.DataOutput
        Overrides:
        writeShort in class BaseDataOutputStream
      • write

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

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

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

        protected void ensureCapacity​(int bytes)
        Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentially
        Specified by:
        ensureCapacity in class BaseDataOutputStream