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.lang.String
asString()
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.protected void
setBuffer(java.nio.ByteBuffer newBuffer)
byte[]
toByteArray()
java.nio.ByteBuffer
unsafeGetBufferAndFlip()
Gets the underlying ByteBuffer and callsByteBuffer.flip()
.-
Methods inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
allocate, order, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeMostSignificantBytes, 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
bytesLeftInPage, maxBytesInPage, paddedPosition, padToPageBoundary, write, writeUnsignedVInt, writeUnsignedVInt, writeUnsignedVInt32, writeVInt, writeVInt, writeVInt32
-
-
-
-
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 #close() 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)
-
setBuffer
protected void setBuffer(java.nio.ByteBuffer newBuffer)
-
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)
-
unsafeGetBufferAndFlip
public java.nio.ByteBuffer unsafeGetBufferAndFlip()
Gets the underlying ByteBuffer and callsByteBuffer.flip()
. This method is "unsafe" in the sense that it returns the underlying buffer, which may be modified by other methods after calling this method (or cleared onclose()
). If the calling logic knows that no new calls to this object will happen after calling this method, then this method can avoid the copying done inasNewBuffer()
, andbuffer()
.
-
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()
-
asString
public java.lang.String asString()
-
-