List of usage examples for io.netty.buffer Unpooled directBuffer
public static ByteBuf directBuffer(int initialCapacity, int maxCapacity)
From source file:io.vertx.proton.impl.ProtonReadableBufferImplTest.java
License:Apache License
@Test public void testGetBytesToWritableBufferThatIsDirect() { byte[] data = new byte[] { 0, 1, 2, 3, 4 }; ByteBuf byteBuffer = Unpooled.directBuffer(data.length, data.length); byteBuffer.writeBytes(data);/*from w w w .jav a 2 s . co m*/ ProtonReadableBufferImpl buffer = new ProtonReadableBufferImpl(byteBuffer); ByteBuf targetBuffer = Unpooled.buffer(data.length, data.length); ProtonWritableBufferImpl target = new ProtonWritableBufferImpl(targetBuffer); buffer.get(target); assertFalse(buffer.hasRemaining()); for (int i = 0; i < data.length; i++) { assertEquals(data[i], target.getBuffer().readByte()); } }
From source file:org.apache.activemq.artemis.protocol.amqp.util.NettyReadableTest.java
License:Apache License
@Test public void testGetBytesToWritableBufferThatIsDirect() { byte[] data = new byte[] { 0, 1, 2, 3, 4 }; ByteBuf byteBuffer = Unpooled.directBuffer(data.length, data.length); byteBuffer.writeBytes(data);/*from w w w .ja v a 2s . c om*/ NettyReadable buffer = new NettyReadable(byteBuffer); ByteBuf targetBuffer = Unpooled.buffer(data.length, data.length); NettyWritable target = new NettyWritable(targetBuffer); buffer.get(target); assertFalse(buffer.hasRemaining()); for (int i = 0; i < data.length; i++) { assertEquals(data[i], target.getByteBuf().readByte()); } }
From source file:org.apache.activemq.artemis.tests.extras.benchmarks.journal.gcfree.EncodersBench.java
License:Apache License
@Setup public void init() { this.byteBuffer = ByteBuffer.allocateDirect(expectedEncoderSize); this.byteBuffer.order(ByteOrder.nativeOrder()); this.addJournalRecordEncoder = new AddJournalRecordEncoder(); this.record = new JournalAddRecord(true, 1, (byte) 1, ZeroEncodingSupport.Instance); this.record.setFileID(1); this.record.setCompactCount((short) 1); this.outBuffer = new ChannelBufferWrapper( Unpooled.directBuffer(this.record.getEncodeSize(), this.record.getEncodeSize()) .order(ByteOrder.nativeOrder())); }
From source file:org.apache.bookkeeper.bookie.storage.ldb.ReadCache.java
License:Apache License
public ReadCache(ByteBufAllocator allocator, long maxCacheSize, int maxSegmentSize) { this.allocator = allocator; int segmentsCount = Math.max(2, (int) (maxCacheSize / maxSegmentSize)); segmentSize = (int) (maxCacheSize / segmentsCount); cacheSegments = new ArrayList<>(); cacheIndexes = new ArrayList<>(); for (int i = 0; i < segmentsCount; i++) { cacheSegments.add(Unpooled.directBuffer(segmentSize, segmentSize)); cacheIndexes/*from www .ja va 2 s . c om*/ .add(new ConcurrentLongLongPairHashMap(4096, 2 * Runtime.getRuntime().availableProcessors())); } }
From source file:org.apache.bookkeeper.bookie.storage.ldb.WriteCache.java
License:Apache License
public WriteCache(ByteBufAllocator allocator, long maxCacheSize, int maxSegmentSize) { checkArgument(maxSegmentSize > 0); long alignedMaxSegmentSize = alignToPowerOfTwo(maxSegmentSize); checkArgument(maxSegmentSize == alignedMaxSegmentSize, "Max segment size needs to be in form of 2^n"); this.allocator = allocator; this.maxCacheSize = maxCacheSize; this.maxSegmentSize = (int) maxSegmentSize; this.segmentOffsetMask = maxSegmentSize - 1; this.segmentOffsetBits = 63 - Long.numberOfLeadingZeros(maxSegmentSize); this.segmentsCount = 1 + (int) (maxCacheSize / maxSegmentSize); this.cacheSegments = new ByteBuf[segmentsCount]; for (int i = 0; i < segmentsCount - 1; i++) { // All intermediate segments will be full-size cacheSegments[i] = Unpooled.directBuffer(maxSegmentSize, maxSegmentSize); }/*from www.ja v a 2 s . c o m*/ int lastSegmentSize = (int) (maxCacheSize % maxSegmentSize); cacheSegments[segmentsCount - 1] = Unpooled.directBuffer(lastSegmentSize, lastSegmentSize); }
From source file:org.apache.qpid.jms.provider.amqp.message.AmqpReadableBufferTest.java
License:Apache License
@Test public void testGetBytesToWritableBufferThatIsDirect() { byte[] data = new byte[] { 0, 1, 2, 3, 4 }; ByteBuf byteBuffer = Unpooled.directBuffer(data.length, data.length); byteBuffer.writeBytes(data);//from w ww. j av a 2 s. c o m AmqpReadableBuffer buffer = new AmqpReadableBuffer(byteBuffer); ByteBuf targetBuffer = Unpooled.buffer(data.length, data.length); AmqpWritableBuffer target = new AmqpWritableBuffer(targetBuffer); buffer.get(target); assertFalse(buffer.hasRemaining()); for (int i = 0; i < data.length; i++) { assertEquals(data[i], target.getBuffer().readByte()); } }