Java源码示例:org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf

示例1
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	// receiver ID (16), sequence number (4), backlog (4), isBuffer (1), buffer size (4)
	final int messageHeaderLength = 16 + 4 + 4 + 1 + 4;

	ByteBuf headerBuf = null;
	try {
		if (buffer instanceof Buffer) {
			// in order to forward the buffer to netty, it needs an allocator set
			((Buffer) buffer).setAllocator(allocator);
		}

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, messageHeaderLength, buffer.readableBytes(), false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeBoolean(isBuffer);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer);
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.release();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
示例2
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	// receiver ID (16), sequence number (4), backlog (4), isBuffer (1), buffer size (4)
	final int messageHeaderLength = 16 + 4 + 4 + 1 + 4;

	ByteBuf headerBuf = null;
	try {
		if (buffer instanceof Buffer) {
			// in order to forward the buffer to netty, it needs an allocator set
			((Buffer) buffer).setAllocator(allocator);
		}

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, messageHeaderLength, buffer.readableBytes(), false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeBoolean(isBuffer);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer);
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.release();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
示例3
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	ByteBuf headerBuf = null;
	try {
		// in order to forward the buffer to netty, it needs an allocator set
		buffer.setAllocator(allocator);

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, MESSAGE_HEADER_LENGTH, bufferSize, false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeByte(dataType.ordinal());
		headerBuf.writeBoolean(isCompressed);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer.asByteBuf());
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.asByteBuf().writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.recycleBuffer();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
示例4
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例5
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例6
@Override
public CompositeByteBuf compositeBuffer() {
	return alloc.compositeBuffer();
}
 
示例7
@Override
public CompositeByteBuf compositeBuffer(int maxNumComponents) {
	return alloc.compositeBuffer(maxNumComponents);
}
 
示例8
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例9
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例10
@Override
public CompositeByteBuf compositeDirectBuffer() {
	return alloc.compositeDirectBuffer();
}
 
示例11
@Override
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
	return alloc.compositeDirectBuffer(maxNumComponents);
}
 
示例12
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例13
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例14
@Override
public CompositeByteBuf compositeBuffer() {
	return alloc.compositeBuffer();
}
 
示例15
@Override
public CompositeByteBuf compositeBuffer(int maxNumComponents) {
	return alloc.compositeBuffer(maxNumComponents);
}
 
示例16
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例17
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例18
@Override
public CompositeByteBuf compositeDirectBuffer() {
	return alloc.compositeDirectBuffer();
}
 
示例19
@Override
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
	return alloc.compositeDirectBuffer(maxNumComponents);
}
 
示例20
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例21
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例22
@Override
public CompositeByteBuf compositeBuffer() {
	return alloc.compositeBuffer();
}
 
示例23
@Override
public CompositeByteBuf compositeBuffer(int maxNumComponents) {
	return alloc.compositeBuffer(maxNumComponents);
}
 
示例24
@Override
public CompositeByteBuf compositeHeapBuffer() {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例25
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
	throw new UnsupportedOperationException("Heap buffer");
}
 
示例26
@Override
public CompositeByteBuf compositeDirectBuffer() {
	return alloc.compositeDirectBuffer();
}
 
示例27
@Override
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
	return alloc.compositeDirectBuffer(maxNumComponents);
}