org.apache.cassandra.io.util

## Class DataOutputBuffer

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.cassandra.io.util.AbstractDataOutput
    - - org.apache.cassandra.io.util.DataOutputStreamPlus
      - - org.apache.cassandra.io.util.DataOutputBuffer

- All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable, DataOutputPlus

      public final class DataOutputBuffer
      extends DataOutputStreamPlus

  An implementation of the DataOutputStream interface using a FastByteArrayOutputStream and exposing its buffer so copies can be avoided. This class is completely thread unsafe.

- - ### Field Summary

    - ### Fields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataOutputBuffer()`
    `DataOutputBuffer(int size)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.nio.ByteBuffer` | `asByteBuffer()`
    `byte[]` | `getData()` Returns the current contents of the buffer.
    `int` | `getLength()` Returns the length of the valid data currently in the buffer.
    `byte[]` | `toByteArray()`
    `void` | `write(byte[] b, int off, int len)` Writes `count` bytes from the byte array `buffer` starting at `offset` to this RandomAccessFile starting at the current file pointer..
    `void` | `write(java.nio.ByteBuffer buffer)`
    `void` | `write(int b)` Writes the specified byte `oneByte` to this RandomAccessFile starting at the current file pointer.

    - ### Methods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus

      `close, flush`

    - ### Methods inherited from class org.apache.cassandra.io.util.AbstractDataOutput

      `write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.cassandra.io.util.DataOutputPlus

      `write`

    - ### Methods inherited from interface java.io.DataOutput

      `write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF`

- - ### Constructor Detail

    - #### DataOutputBuffer

          public DataOutputBuffer()

    - #### DataOutputBuffer

          public DataOutputBuffer(int size)

  - ### Method Detail

    - #### write

          public void write(int b)

      Description copied from class: `AbstractDataOutput`
      Writes the specified byte `oneByte` to this RandomAccessFile starting at the current file pointer. Only the low order byte of `oneByte` is written.
      Specified by:
        `write` in interface `java.io.DataOutput`
      Overrides:
        `write` in class `DataOutputStreamPlus`
      Parameters:
        `b` - the byte to be written

    - #### write

          public void write(byte[] b,
                   int off,
                   int len)

      Description copied from class: `AbstractDataOutput`
      Writes `count` bytes from the byte array `buffer` starting at `offset` to this RandomAccessFile starting at the current file pointer..
      Specified by:
        `write` in interface `java.io.DataOutput`
      Overrides:
        `write` in class `DataOutputStreamPlus`
      Parameters:
        `b` - the bytes to be written
        `off` - offset in buffer to get bytes
        `len` - number of bytes in buffer to write

    - #### write

          public void write(java.nio.ByteBuffer buffer)
                     throws java.io.IOException

      Specified by:
        `write` in interface `DataOutputPlus`
      Overrides:
        `write` in class `AbstractDataOutput`
      Throws:
        `java.io.IOException`

    - #### getData

          public byte[] getData()

      Returns the current contents of the buffer. Data is only valid to `getLength()`.

    - #### toByteArray

          public byte[] toByteArray()

    - #### asByteBuffer

          public java.nio.ByteBuffer asByteBuffer()

    - #### getLength

          public int getLength()

      Returns the length of the valid data currently in the buffer.

Copyright © 2014 The Apache Software Foundation