public final class ChannelWriterOutputView extends AbstractPagedOutputView
DataOutputView
that is backed by a BlockChannelWriter
, making it effectively a data output stream. The view writes its data in
blocks to the underlying channel, adding a minimal header to each block. The data can be re-read
by a ChannelReaderInputView
, if it uses the same block size.Modifier and Type | Field and Description |
---|---|
protected static short |
FLAG_LAST_BLOCK
The flag marking a block as the last block.
|
protected static int |
HEAD_BLOCK_LENGTH_OFFSET
The offset to the header field indicating the number of bytes in the block
|
protected static int |
HEADER_FLAGS_OFFSET
The offset to the flags in the header;
|
protected static int |
HEADER_LENGTH
The length of the header put into the blocks.
|
protected static short |
HEADER_MAGIC_NUMBER
The magic number that identifies blocks as blocks from a ChannelWriterOutputView.
|
headerLength, segmentSize
Constructor and Description |
---|
ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer,
int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel.
|
ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer,
List<MemorySegment> memory,
int segmentSize)
Creates an new ChannelWriterOutputView that writes to the given channel and buffers data in
the given memory segments.
|
Modifier and Type | Method and Description |
---|---|
List<MemorySegment> |
close()
Closes this OutputView, closing the underlying writer and returning all memory segments.
|
int |
getBlockCount()
Gets the number of blocks used by this view.
|
long |
getBytesMemoryUsed()
Gets the number of bytes used by this output view, including written bytes and header bytes.
|
long |
getBytesWritten()
Gets the number of pay-load bytes already written.
|
protected MemorySegment |
nextSegment(MemorySegment current,
int posInSegment)
This method must return a segment.
|
advance, clear, getCurrentPositionInSegment, getCurrentSegment, getHeaderLength, getSegmentSize, seekOutput, skipBytesToWrite, write, write, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
protected static final short HEADER_MAGIC_NUMBER
protected static final int HEADER_LENGTH
protected static final int HEADER_FLAGS_OFFSET
protected static final int HEAD_BLOCK_LENGTH_OFFSET
protected static final short FLAG_LAST_BLOCK
public ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, List<MemorySegment> memory, int segmentSize)
writer
- The writer to write to.memory
- The memory used to buffer data, or null, to utilize solely the return queue.segmentSize
- The size of the memory segments.public ChannelWriterOutputView(BlockChannelWriter<MemorySegment> writer, int segmentSize)
writer
- The writer to write to.segmentSize
- The size of the memory segments.public List<MemorySegment> close() throws IOException
IOException
- Thrown, if the underlying writer could not be properly closed.public int getBlockCount()
public long getBytesWritten()
public long getBytesMemoryUsed()
protected final MemorySegment nextSegment(MemorySegment current, int posInSegment) throws IOException
AbstractPagedOutputView
EOFException
.nextSegment
in class AbstractPagedOutputView
current
- The current memory segmentposInSegment
- The position in the segment, one after the last valid byte.IOException
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.