@NotThreadSafe public class BufferBuilder extends Object implements AutoCloseable
MemorySegment
. To access written
data please use BufferConsumer
which allows to build Buffer
instances from the
written data.Constructor and Description |
---|
BufferBuilder(MemorySegment memorySegment,
BufferRecycler recycler) |
Modifier and Type | Method and Description |
---|---|
int |
append(ByteBuffer source)
Append as many data as possible from
source . |
int |
appendAndCommit(ByteBuffer source)
Same as
append(ByteBuffer) but additionally commit() the appending. |
void |
close() |
void |
commit()
Make the change visible to the readers.
|
BufferConsumer |
createBufferConsumer()
This method always creates a
BufferConsumer starting from the current writer offset. |
BufferConsumer |
createBufferConsumerFromBeginning()
This method always creates a
BufferConsumer starting from position 0 of MemorySegment . |
int |
finish()
Mark this
BufferBuilder and associated BufferConsumer as finished - no new
data writes will be allowed. |
int |
getCommittedBytes() |
Buffer.DataType |
getDataType()
Gets the data type of the internal buffer.
|
int |
getMaxCapacity() |
int |
getWritableBytes() |
boolean |
isFinished() |
boolean |
isFull() |
void |
setDataType(Buffer.DataType dataType)
Sets the data type of the internal buffer.
|
void |
trim(int newSize)
The result capacity can not be greater than allocated memorySegment.
|
public BufferBuilder(MemorySegment memorySegment, BufferRecycler recycler)
public BufferConsumer createBufferConsumer()
BufferConsumer
starting from the current writer offset.
Data written to BufferBuilder
before creation of BufferConsumer
won't be
visible for that BufferConsumer
.BufferConsumer
to this BufferBuilder
.public BufferConsumer createBufferConsumerFromBeginning()
BufferConsumer
starting from position 0 of MemorySegment
.BufferConsumer
to this BufferBuilder
.public Buffer.DataType getDataType()
public void setDataType(Buffer.DataType dataType)
public int appendAndCommit(ByteBuffer source)
append(ByteBuffer)
but additionally commit()
the appending.public int append(ByteBuffer source)
source
. Not everything might be copied if there
is not enough space in the underlying MemorySegment
public void commit()
public int finish()
BufferBuilder
and associated BufferConsumer
as finished - no new
data writes will be allowed.
This method should be idempotent to handle failures and task interruptions. Check FLINK-8948 for more details.
public boolean isFinished()
public boolean isFull()
public int getWritableBytes()
public int getCommittedBytes()
public int getMaxCapacity()
public void trim(int newSize)
public void close()
close
in interface AutoCloseable
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.