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:
Closeable,DataOutput,Flushable,AutoCloseable,DataOutputPlus
- Direct Known Subclasses:
DataOutputBufferFixed,SafeMemoryWriter
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
FieldsModifier and TypeFieldDescriptionstatic final io.netty.util.concurrent.FastThreadLocal<DataOutputBuffer>Scratch buffers used mostly for serializing in memory.Fields inherited from class org.apache.cassandra.io.util.BufferedDataOutputStreamPlus
bufferFields inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
channel -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasString()buffer()buffer(boolean duplicate) voidclear()voidclose()protected voiddoFlush(int count) protected voidexpandToFit(long count) voidflush()byte[]getData()intbooleanIf the implementation supports providing a position, this method returnstrue, otherwisefalse.protected WritableByteChannellongposition()Returns the current position of the underlying target like a file-pointer or the position withing a buffer.protected voidsetBuffer(ByteBuffer newBuffer) byte[]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, writeUTFMethods inherited from class org.apache.cassandra.io.util.DataOutputStreamPlus
retrieveTemporaryBufferMethods inherited from class java.io.OutputStream
nullOutputStreamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.io.util.DataOutputPlus
bytesLeftInPage, maxBytesInPage, paddedPosition, padToPageBoundary, write, writeUnsignedVInt, writeUnsignedVInt, writeUnsignedVInt32, writeVInt, writeVInt, writeVInt32
-
Field Details
-
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.
-
-
Constructor Details
-
DataOutputBuffer
public DataOutputBuffer() -
DataOutputBuffer
public DataOutputBuffer(int size) -
DataOutputBuffer
-
-
Method Details
-
flush
public void flush()- Specified by:
flushin interfaceFlushable- Overrides:
flushin classBufferedDataOutputStreamPlus
-
doFlush
- Overrides:
doFlushin classBufferedDataOutputStreamPlus- Throws:
IOException
-
expandToFit
protected void expandToFit(long count) -
setBuffer
-
newDefaultChannel
- Overrides:
newDefaultChannelin classDataOutputStreamPlus
-
clear
public void clear() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classBufferedDataOutputStreamPlus
-
buffer
-
buffer
-
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:DataOutputPlusIf the implementation supports providing a position, this method returnstrue, otherwisefalse. -
position
public long position()Description copied from interface:DataOutputPlusReturns 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
-
toByteArray
public byte[] toByteArray() -
asString
-