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

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#getBytes() . 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: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void testGetReadOnlyDst(boolean direct) {
    byte[] bytes = { 'a', 'b', 'c', 'd' };

    ByteBuf buffer = newBuffer(bytes.length);
    buffer.writeBytes(bytes);

    ByteBuffer dst = direct ? ByteBuffer.allocateDirect(bytes.length) : ByteBuffer.allocate(bytes.length);
    ByteBuffer readOnlyDst = dst.asReadOnlyBuffer();
    try {
        buffer.getBytes(0, readOnlyDst);
        fail();
    } catch (ReadOnlyBufferException e) {
        // expected
    }
    assertEquals(0, readOnlyDst.position());
    buffer.release();
}
 
Example 2
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void testGetReadOnlyDst(boolean direct) {
    byte[] bytes = { 'a', 'b', 'c', 'd' };

    ByteBuf buffer = newBuffer(bytes.length);
    buffer.writeBytes(bytes);

    ByteBuffer dst = direct ? ByteBuffer.allocateDirect(bytes.length) : ByteBuffer.allocate(bytes.length);
    ByteBuffer readOnlyDst = dst.asReadOnlyBuffer();
    try {
        buffer.getBytes(0, readOnlyDst);
        fail();
    } catch (ReadOnlyBufferException e) {
        // expected
    }
    assertEquals(0, readOnlyDst.position());
    buffer.release();
}
 
Example 3
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void testGetReadOnlyDst(boolean direct) {
    byte[] bytes = { 'a', 'b', 'c', 'd' };

    ByteBuf buffer = newBuffer(bytes.length);
    buffer.writeBytes(bytes);

    ByteBuffer dst = direct ? ByteBuffer.allocateDirect(bytes.length) : ByteBuffer.allocate(bytes.length);
    ByteBuffer readOnlyDst = dst.asReadOnlyBuffer();
    try {
        buffer.getBytes(0, readOnlyDst);
        fail();
    } catch (ReadOnlyBufferException e) {
        // expected
    }
    assertEquals(0, readOnlyDst.position());
    buffer.release();
}
 
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(expected = IndexOutOfBoundsException.class)
public void testGetBytesByteBuffer() {
    byte[] bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
    // Ensure destination buffer is bigger then what is in the ByteBuf.
    ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
    ByteBuf buffer = newBuffer(bytes.length);
    try {
        buffer.writeBytes(bytes);
        buffer.getBytes(buffer.readerIndex(), nioBuffer);
    } finally {
        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(expected = IndexOutOfBoundsException.class)
public void testGetBytesByteBuffer() {
    byte[] bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
    // Ensure destination buffer is bigger then what is in the ByteBuf.
    ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
    ByteBuf buffer = newBuffer(bytes.length);
    try {
        buffer.writeBytes(bytes);
        buffer.getBytes(buffer.readerIndex(), nioBuffer);
    } finally {
        buffer.release();
    }
}
 
Example 8
Source File: ChannelStateSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeData(DataOutputStream stream, Buffer... flinkBuffers) throws IOException {
	stream.writeInt(getSize(flinkBuffers));
	for (Buffer buffer : flinkBuffers) {
		ByteBuf nettyByteBuf = buffer.asByteBuf();
		nettyByteBuf.getBytes(nettyByteBuf.readerIndex(), stream, nettyByteBuf.readableBytes());
	}
}
 
Example 9
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 10
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesByteBuffer() {
    byte[] bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
    // Ensure destination buffer is bigger then what is in the ByteBuf.
    ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
    ByteBuf buffer = newBuffer(bytes.length);
    try {
        buffer.writeBytes(bytes);
        buffer.getBytes(buffer.readerIndex(), nioBuffer);
    } finally {
        buffer.release();
    }
}