use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project elasticsearch by elastic.
the class Netty4UtilsTests method testToChannelBuffer.
public void testToChannelBuffer() throws IOException {
BytesReference ref = getRandomizedBytesReference(randomIntBetween(1, 3 * PAGE_SIZE));
ByteBuf buffer = Netty4Utils.toByteBuf(ref);
BytesReference bytesReference = Netty4Utils.toBytesReference(buffer);
if (ref instanceof ByteBufBytesReference) {
assertEquals(buffer, ((ByteBufBytesReference) ref).toByteBuf());
} else if (AbstractBytesReferenceTestCase.getNumPages(ref) > 1) {
// we gather the buffers into a channel buffer
assertTrue(buffer instanceof CompositeByteBuf);
}
assertArrayEquals(BytesReference.toBytes(ref), BytesReference.toBytes(bytesReference));
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project vert.x by eclipse.
the class Http2ConnectionBase method safeBuffer.
/**
* Return a buffer from HTTP/2 codec that Vert.x can use:
*
* - if it's a direct buffer (coming likely from OpenSSL) : we get a heap buffer version
* - if it's a composite buffer we do the same
* - otherwise we increase the ref count
*/
static ByteBuf safeBuffer(ByteBuf buf, ByteBufAllocator allocator) {
if (buf == Unpooled.EMPTY_BUFFER) {
return buf;
}
if (buf.isDirect() || buf instanceof CompositeByteBuf) {
if (buf.isReadable()) {
ByteBuf buffer = allocator.heapBuffer(buf.readableBytes());
buffer.writeBytes(buf);
return buffer;
} else {
return Unpooled.EMPTY_BUFFER;
}
}
return buf.retain();
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class CoalescingBufferQueue method compose.
/**
* Compose the current buffer with another.
*/
private ByteBuf compose(ByteBuf current, ByteBuf next) {
if (current == null) {
return next;
}
if (current instanceof CompositeByteBuf) {
CompositeByteBuf composite = (CompositeByteBuf) current;
composite.addComponent(true, next);
return composite;
}
// Create a composite buffer to accumulate this pair and potentially all the buffers
// in the queue. Using +2 as we have already dequeued current and next.
CompositeByteBuf composite = channel.alloc().compositeBuffer(bufAndListenerPairs.size() + 2);
composite.addComponent(true, current);
composite.addComponent(true, next);
return composite;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project java-in-action by xinghalo.
the class CompositeTest method main.
public static void main(String[] args) {
// 组合缓冲区
CompositeByteBuf compBuf = Unpooled.compositeBuffer();
ByteBuf header = Unpooled.buffer(8);
header.writeBytes("aaaabbbb".getBytes());
ByteBuf body = Unpooled.buffer(8);
body.writeBytes("11112222".getBytes());
// 添加ByteBuf到CompositeByteBuf
compBuf.addComponents(header, body);
System.out.println(compBuf.toString());
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project x-pipe by ctripcorp.
the class ArrayParser method getWriteByteBuf.
@Override
protected ByteBuf getWriteByteBuf() {
int length = payload.length;
CompositeByteBuf result = new CompositeByteBuf(UnpooledByteBufAllocator.DEFAULT, false, payload.length + 1);
String prefix = String.format("%c%d\r\n", ASTERISK_BYTE, length);
result.addComponent(Unpooled.wrappedBuffer(prefix.getBytes()));
for (Object o : payload) {
ByteBuf buff = ParserManager.parse(o);
result.addComponent(buff);
}
result.setIndex(0, result.capacity());
return result;
}
Aggregations