@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer(singularArguments.size() * 10); encode(buffer); buffer.resetReaderIndex(); byte[] bytes = new byte[buffer.readableBytes()]; buffer.readBytes(bytes); sb.append(" [buffer=").append(new String(bytes)); sb.append(']'); buffer.release(); return sb.toString(); }
public static byte[] longToBytes(long x) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8); buffer.writeLong(x); return buffer.array(); }
@Parameterized.Parameters(name = "{0}") public static Object[][] buffers() { return new Object[][]{ {new NettyDataBufferFactory(new UnpooledByteBufAllocator(true))}, {new NettyDataBufferFactory(new UnpooledByteBufAllocator(false))}, {new NettyDataBufferFactory(new PooledByteBufAllocator(true))}, {new NettyDataBufferFactory(new PooledByteBufAllocator(false))}}; }
@Override protected byte[] allocateArray(int initialCapacity) { byte[] bytes = super.allocateArray(initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementHeap(bytes.length); return bytes; }
@Override public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) { CompositeByteBuf buf = new CompositeByteBuf(this, false, maxNumComponents); return disableLeakDetector ? buf : toLeakAwareBuffer(buf); }
@Override protected void freeDirect(ByteBuffer buffer) { int capacity = buffer.capacity(); super.freeDirect(buffer); ((UnpooledByteBufAllocator) alloc()).decrementDirect(capacity); } }
@Override protected void freeArray(byte[] array) { int length = array.length; super.freeArray(array); ((UnpooledByteBufAllocator) alloc()).decrementHeap(length); } }
@Override ByteBuffer reallocateDirect(ByteBuffer oldBuffer, int initialCapacity) { int capacity = oldBuffer.capacity(); ByteBuffer buffer = super.reallocateDirect(oldBuffer, initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementDirect(buffer.capacity() - capacity); return buffer; }
@Override protected byte[] allocateArray(int initialCapacity) { byte[] bytes = super.allocateArray(initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementHeap(bytes.length); return bytes; }
@Override public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) { CompositeByteBuf buf = new CompositeByteBuf(this, true, maxNumComponents); return disableLeakDetector ? buf : toLeakAwareBuffer(buf); }
@Override protected void freeDirect(ByteBuffer buffer) { int capacity = buffer.capacity(); super.freeDirect(buffer); ((UnpooledByteBufAllocator) alloc()).decrementDirect(capacity); } }
@Override protected void freeArray(byte[] array) { int length = array.length; super.freeArray(array); ((UnpooledByteBufAllocator) alloc()).decrementHeap(length); } }
@Override protected ByteBuffer allocateDirect(int initialCapacity) { ByteBuffer buffer = super.allocateDirect(initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementDirect(buffer.capacity()); return buffer; }
final ByteBuf intermediate = UnpooledByteBufAllocator.DEFAULT.buffer(intermediateBytes.length); try { intermediate.setBytes(0, intermediateBytes);
private ActiveMQBuffer getLargeMessageBuffer() throws ActiveMQException { ActiveMQBuffer buffer; LargeBodyEncoder encoder = getBodyEncoder(); encoder.open(); int bodySize = (int) encoder.getLargeBodySize(); buffer = new ChannelBufferWrapper(UnpooledByteBufAllocator.DEFAULT.heapBuffer(bodySize)); encoder.encode(buffer, bodySize); encoder.close(); return buffer; }
@Override protected byte[] allocateArray(int initialCapacity) { byte[] bytes = super.allocateArray(initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementHeap(bytes.length); return bytes; }
@Override public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) { CompositeByteBuf buf = new CompositeByteBuf(this, true, maxNumComponents); return disableLeakDetector ? buf : toLeakAwareBuffer(buf); }
@Override protected void freeDirect(ByteBuffer buffer) { int capacity = buffer.capacity(); super.freeDirect(buffer); ((UnpooledByteBufAllocator) alloc()).decrementDirect(capacity); } }
@Override protected void freeArray(byte[] array) { int length = array.length; super.freeArray(array); ((UnpooledByteBufAllocator) alloc()).decrementHeap(length); } }
@Override protected ByteBuffer allocateDirect(int initialCapacity) { ByteBuffer buffer = super.allocateDirect(initialCapacity); ((UnpooledByteBufAllocator) alloc()).incrementDirect(buffer.capacity()); return buffer; }