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()
      • 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