Package 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 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
-
Fields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
channel
-
-
Constructor Summary
Constructors Constructor Description DataOutputBuffer()
DataOutputBuffer(int size)
DataOutputBuffer(java.nio.ByteBuffer buffer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffer
asNewBuffer()
java.nio.ByteBuffer
buffer()
java.nio.ByteBuffer
buffer(boolean duplicate)
void
clear()
void
close()
protected void
doFlush(int count)
protected void
expandToFit(long count)
void
flush()
byte[]
getData()
int
getLength()
boolean
hasPosition()
If the implementation supports providing a position, this method returnstrue
, otherwisefalse
.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.byte[]
toByteArray()
-
Methods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
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
-
Methods inherited from interface org.apache.cassandra.io.util.DataOutputPlus
write, writeUnsignedVInt, writeVInt
-
-
-
-
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.
-
-
Method Detail
-
flush
public void flush()
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classBufferedDataOutputStreamPlus
-
doFlush
protected void doFlush(int count) throws java.io.IOException
- Overrides:
doFlush
in classBufferedDataOutputStreamPlus
- Throws:
java.io.IOException
-
expandToFit
protected void expandToFit(long count)
-
newDefaultChannel
protected java.nio.channels.WritableByteChannel newDefaultChannel()
- Overrides:
newDefaultChannel
in classDataOutputStreamPlus
-
clear
public void clear()
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classBufferedDataOutputStreamPlus
-
buffer
public java.nio.ByteBuffer buffer()
-
buffer
public java.nio.ByteBuffer buffer(boolean duplicate)
-
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 returnstrue
, otherwisefalse
.
-
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 theDataOutputPlus.hasPosition()
.
-
asNewBuffer
public java.nio.ByteBuffer asNewBuffer()
-
toByteArray
public byte[] toByteArray()
-
-