Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#nioBuffers()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#nioBuffers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkBuffer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkDstIndex(index, length, dstIndex, dst.capacity());

	if (dst.hasArray()) {
		getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
	} else if (dst.nioBufferCount() > 0) {
		for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) {
			int bbLen = bb.remaining();
			getBytes(index, bb);
			index += bbLen;
		}
	} else {
		dst.setBytes(dstIndex, this, index, length);
	}
	return this;
}
 
Example 2
Source File: NetworkBuffer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkDstIndex(index, length, dstIndex, dst.capacity());

	if (dst.hasArray()) {
		getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
	} else if (dst.nioBufferCount() > 0) {
		for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) {
			int bbLen = bb.remaining();
			getBytes(index, bb);
			index += bbLen;
		}
	} else {
		dst.setBytes(dstIndex, this, index, length);
	}
	return this;
}
 
Example 3
Source File: NetworkBuffer.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkDstIndex(index, length, dstIndex, dst.capacity());

	if (dst.hasArray()) {
		getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
	} else if (dst.nioBufferCount() > 0) {
		for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) {
			int bbLen = bb.remaining();
			getBytes(index, bb);
			index += bbLen;
		}
	} else {
		dst.setBytes(dstIndex, this, index, length);
	}
	return this;
}
 
Example 4
Source File: NetworkBuffer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkSrcIndex(index, length, srcIndex, src.capacity());
	if (src.nioBufferCount() > 0) {
		for (ByteBuffer bb: src.nioBuffers(srcIndex, length)) {
			int bbLen = bb.remaining();
			setBytes(index, bb);
			index += bbLen;
		}
	} else {
		src.getBytes(srcIndex, this, index, length);
	}
	return this;
}
 
Example 5
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyNioBuffers() throws Exception {
    ByteBuf buffer = newBuffer(8);
    buffer.clear();
    assertFalse(buffer.isReadable());
    ByteBuffer[] nioBuffers = buffer.nioBuffers();
    assertEquals(1, nioBuffers.length);
    assertFalse(nioBuffers[0].hasRemaining());
    buffer.release();
}
 
Example 6
Source File: NetworkBuffer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkSrcIndex(index, length, srcIndex, src.capacity());
	if (src.nioBufferCount() > 0) {
		for (ByteBuffer bb: src.nioBuffers(srcIndex, length)) {
			int bbLen = bb.remaining();
			setBytes(index, bb);
			index += bbLen;
		}
	} else {
		src.getBytes(srcIndex, this, index, length);
	}
	return this;
}
 
Example 7
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyNioBuffers() throws Exception {
    ByteBuf buffer = newBuffer(8);
    buffer.clear();
    assertFalse(buffer.isReadable());
    ByteBuffer[] nioBuffers = buffer.nioBuffers();
    assertEquals(1, nioBuffers.length);
    assertFalse(nioBuffers[0].hasRemaining());
    buffer.release();
}
 
Example 8
Source File: NetworkBuffer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
	// from UnpooledDirectByteBuf:
	checkSrcIndex(index, length, srcIndex, src.capacity());
	if (src.nioBufferCount() > 0) {
		for (ByteBuffer bb: src.nioBuffers(srcIndex, length)) {
			int bbLen = bb.remaining();
			setBytes(index, bb);
			index += bbLen;
		}
	} else {
		src.getBytes(srcIndex, this, index, length);
	}
	return this;
}
 
Example 9
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyNioBuffers() throws Exception {
    ByteBuf buffer = newBuffer(8);
    buffer.clear();
    assertFalse(buffer.isReadable());
    ByteBuffer[] nioBuffers = buffer.nioBuffers();
    assertEquals(1, nioBuffers.length);
    assertFalse(nioBuffers[0].hasRemaining());
    buffer.release();
}