Class BufferReaderWriterUtil
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.BufferReaderWriterUtil
-
public final class BufferReaderWriterUtil extends Object
Putting and getting of a sequence of buffers to/from a FileChannel or a ByteBuffer. This class handles the headers, length encoding, memory slicing.The encoding is the same across FileChannel and ByteBuffer, so this class can write to a file and read from the byte buffer that results from mapping this file to memory.
-
-
Field Summary
Fields Modifier and Type Field Description static int
HEADER_LENGTH
-
Constructor Summary
Constructors Constructor Description BufferReaderWriterUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ByteBuffer
allocatedHeaderBuffer()
static BufferHeader
parseBufferHeader(ByteBuffer headerBuffer)
static void
positionToNextBuffer(FileChannel channel, ByteBuffer headerBuffer)
Skip one data buffer from the channel's current position by headerBuffer.static void
readByteBufferFully(FileChannel channel, ByteBuffer b)
static void
readByteBufferFully(FileChannel channel, ByteBuffer b, long position)
static Buffer
readFromByteChannel(FileChannel channel, ByteBuffer headerBuffer, MemorySegment memorySegment, BufferRecycler bufferRecycler)
static void
setByteChannelBufferHeader(Buffer buffer, ByteBuffer header)
static void
writeBuffers(FileChannel channel, long bytesExpected, ByteBuffer... buffers)
-
-
-
Field Detail
-
HEADER_LENGTH
public static final int HEADER_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
setByteChannelBufferHeader
public static void setByteChannelBufferHeader(Buffer buffer, ByteBuffer header)
-
readFromByteChannel
@Nullable public static Buffer readFromByteChannel(FileChannel channel, ByteBuffer headerBuffer, MemorySegment memorySegment, BufferRecycler bufferRecycler) throws IOException
- Throws:
IOException
-
allocatedHeaderBuffer
public static ByteBuffer allocatedHeaderBuffer()
-
positionToNextBuffer
public static void positionToNextBuffer(FileChannel channel, ByteBuffer headerBuffer) throws IOException
Skip one data buffer from the channel's current position by headerBuffer.- Throws:
IOException
-
readByteBufferFully
public static void readByteBufferFully(FileChannel channel, ByteBuffer b) throws IOException
- Throws:
IOException
-
readByteBufferFully
public static void readByteBufferFully(FileChannel channel, ByteBuffer b, long position) throws IOException
- Throws:
IOException
-
writeBuffers
public static void writeBuffers(FileChannel channel, long bytesExpected, ByteBuffer... buffers) throws IOException
- Throws:
IOException
-
parseBufferHeader
public static BufferHeader parseBufferHeader(ByteBuffer headerBuffer)
-
-