DataOutputBuffer (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.io.util

## Class DataOutputBuffer

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

- All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable, DataOutputPlus
  Direct Known Subclasses:
    DataOutputBufferFixed, SafeMemoryWriter

      public class DataOutputBuffer
      extends BufferedDataOutputStreamPlus

  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
    Modifier and Type | Field and Description
    --- | ---
    `static io.netty.util.concurrent.FastThreadLocal<DataOutputBuffer>` | `scratchBuffer` Scratch buffers used mostly for serializing in memory.

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

      `buffer, strictFlushing`

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

      `channel`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataOutputBuffer()`
    `DataOutputBuffer(java.nio.ByteBuffer buffer)`
    `DataOutputBuffer(int size)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.nio.ByteBuffer` | `asNewBuffer()`
    `java.nio.ByteBuffer` | `buffer()`
    `void` | `clear()`
    `void` | `close()`
    `protected void` | `doFlush(int count)`
    `void` | `flush()`
    `byte[]` | `getData()`
    `int` | `getLength()`
    `boolean` | `hasPosition()` If the implementation supports providing a position, this method returns `true`, otherwise `false`.
    `protected java.nio.channels.WritableByteChannel` | `newDefaultChannel()`
    `long` | `position()` Returns the current position of the underlying target like a file-pointer or the position withing a buffer.
    `protected void` | `reallocate(long count)`
    `byte[]` | `toByteArray()`

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

      `applyToChannel, order, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUnsignedVInt, writeUTF, writeVInt`

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

      `retrieveTemporaryBuffer`

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

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

- - ### Field Detail

    - #### scratchBuffer

          public static final io.netty.util.concurrent.FastThreadLocal<DataOutputBuffer> scratchBuffer

      Scratch buffers used mostly for serializing in memory. It's important to call #recycle() when finished to keep the memory overhead from being too large in the system.

  - ### Constructor Detail

    - #### DataOutputBuffer

          public DataOutputBuffer()

    - #### DataOutputBuffer

          public DataOutputBuffer(int size)

    - #### DataOutputBuffer

          public DataOutputBuffer(java.nio.ByteBuffer buffer)

  - ### Method Detail

    - #### flush

          public void flush()
                     throws java.io.IOException

      Specified by:
        `flush` in interface `java.io.Flushable`
      Overrides:
        `flush` in class `BufferedDataOutputStreamPlus`
      Throws:
        `java.io.IOException`

    - #### doFlush

          protected void doFlush(int count)
                          throws java.io.IOException

      Overrides:
        `doFlush` in class `BufferedDataOutputStreamPlus`
      Throws:
        `java.io.IOException`

    - #### reallocate

          protected void reallocate(long count)

    - #### newDefaultChannel

          protected java.nio.channels.WritableByteChannel newDefaultChannel()

      Overrides:
        `newDefaultChannel` in class `DataOutputStreamPlus`

    - #### clear

          public void clear()

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `BufferedDataOutputStreamPlus`

    - #### buffer

          public java.nio.ByteBuffer buffer()

    - #### getData

          public byte[] getData()

    - #### getLength

          public int getLength()

    - #### hasPosition

          public boolean hasPosition()

      Description copied from interface: `DataOutputPlus`
      If the implementation supports providing a position, this method returns `true`, otherwise `false`.

    - #### position

          public long position()

      Description copied from interface: `DataOutputPlus`
      Returns the current position of the underlying target like a file-pointer or the position withing a buffer. Not every implementation may support this functionality. Whether or not this functionality is supported can be checked via the `DataOutputPlus.hasPosition()`.

    - #### asNewBuffer

          public java.nio.ByteBuffer asNewBuffer()

    - #### toByteArray

          public byte[] toByteArray()

Copyright © 2018 The Apache Software Foundation