Class DataByteArrayOutputStream

java.lang.Object
java.io.OutputStream
org.apache.activemq.util.DataByteArrayOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable

public final class DataByteArrayOutputStream extends OutputStream implements DataOutput
Optimized ByteArrayOutputStream
  • Constructor Details

    • DataByteArrayOutputStream

      public DataByteArrayOutputStream(int size)
      Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
      Parameters:
      size - the initial size.
      Throws:
      IllegalArgumentException - if size is negative.
    • DataByteArrayOutputStream

      public DataByteArrayOutputStream()
      Creates a new byte array output stream.
  • Method Details

    • restart

      public void restart(int size)
      start using a fresh byte array
      Parameters:
      size -
    • restart

      public void restart()
      start using a fresh byte array
    • toByteSequence

      public ByteSequence toByteSequence()
      Get a ByteSequence from the stream
      Returns:
      the byte sequence
    • write

      public void write(int b)
      Writes the specified byte to this byte array output stream.
      Specified by:
      write in interface DataOutput
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to be written.
    • write

      public void write(byte[] b, int off, int len)
      Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
      Specified by:
      write in interface DataOutput
      Overrides:
      write in class OutputStream
      Parameters:
      b - the data.
      off - the start offset in the data.
      len - the number of bytes to write.
    • getData

      public byte[] getData()
      Returns:
      the underlying byte[] buffer
    • reset

      public void reset()
      reset the output stream
    • position

      public void position(int offset)
      Set the current position for writing
      Parameters:
      offset -
    • size

      public int size()
    • writeBoolean

      public void writeBoolean(boolean v)
      Specified by:
      writeBoolean in interface DataOutput
    • writeByte

      public void writeByte(int v)
      Specified by:
      writeByte in interface DataOutput
    • writeShort

      public void writeShort(int v)
      Specified by:
      writeShort in interface DataOutput
    • writeChar

      public void writeChar(int v)
      Specified by:
      writeChar in interface DataOutput
    • writeInt

      public void writeInt(int v)
      Specified by:
      writeInt in interface DataOutput
    • writeLong

      public void writeLong(long v)
      Specified by:
      writeLong in interface DataOutput
    • writeFloat

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

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

      public void writeBytes(String s)
      Specified by:
      writeBytes in interface DataOutput
    • writeChars

      public void writeChars(String s)
      Specified by:
      writeChars in interface DataOutput
    • writeUTF

      public void writeUTF(String text) throws IOException
      Specified by:
      writeUTF in interface DataOutput
      Throws:
      IOException