List of usage examples for io.netty.buffer Unpooled wrappedBuffer
static <T> ByteBuf wrappedBuffer(int maxNumComponents, ByteWrapper<T> wrapper, T[] array)
From source file:alluxio.network.protocol.databuffer.ByteArrayDataBuffer.java
License:Apache License
@Override public Object getNettyOutput() { return Unpooled.wrappedBuffer(mByteArray, (int) mOffset, (int) mLength); }
From source file:com.github.ambry.rest.NettyRequestTest.java
License:Open Source License
/** * Generates random content and fills it up (in parts) in {@code httpContents}. * @param httpContents the {@link List<HttpContent>} that will contain all the content in parts. * @return the whole content as a {@link ByteBuffer} - serves as a source of truth. *//* w w w . j a v a 2 s . c o m*/ private ByteBuffer generateContent(List<HttpContent> httpContents) { byte[] contentBytes = RestTestUtils.getRandomBytes(10240); for (int addedContentCount = 0; addedContentCount < 9; addedContentCount++) { HttpContent httpContent = new DefaultHttpContent( Unpooled.wrappedBuffer(contentBytes, addedContentCount * 1024, 1024)); httpContents.add(httpContent); } httpContents.add(new DefaultLastHttpContent(Unpooled.wrappedBuffer(contentBytes, 9 * 1024, 1024))); return ByteBuffer.wrap(contentBytes); }
From source file:com.github.jrialland.ajpclient.pool.Buffers.java
License:Apache License
public static ByteBuf wrap(byte[] array, int offset, int len) { return Unpooled.wrappedBuffer(array, offset, len); }
From source file:com.linecorp.armeria.client.encoding.ZlibStreamDecoder.java
License:Apache License
@Override public HttpData decode(HttpData obj) { if (obj instanceof ByteBufHolder) { decoder.writeInbound(((ByteBufHolder) obj).content()); } else {/*from w w w . j a v a2s. c o m*/ final ByteBuf compressed = Unpooled.wrappedBuffer(obj.array(), obj.offset(), obj.length()); decoder.writeInbound(compressed); } return HttpData.of(fetchDecoderOutput()); }
From source file:com.linecorp.armeria.client.http.encoding.ZlibStreamDecoder.java
License:Apache License
@Override public HttpData decode(HttpData obj) { ByteBuf compressed = Unpooled.wrappedBuffer(obj.array(), obj.offset(), obj.length()); decoder.writeInbound(compressed);//from w w w . j ava 2 s . c o m return HttpData.of(fetchDecoderOutput()); }
From source file:com.linecorp.armeria.internal.Http1ObjectEncoder.java
License:Apache License
private static ByteBuf dataChunk(HttpData data, int offset, int chunkSize) { if (data instanceof ByteBufHolder) { final ByteBuf buf = ((ByteBufHolder) data).content(); return buf.retainedSlice(offset, chunkSize); } else {//from www . ja va 2 s. com return Unpooled.wrappedBuffer(data.array(), offset, chunkSize); } }
From source file:com.linecorp.armeria.server.thrift.THttp2Client.java
License:Apache License
@Override public void flush() throws TTransportException { THttp2ClientInitializer initHandler = new THttp2ClientInitializer(); Bootstrap b = new Bootstrap(); b.group(group);/*from w w w . ja v a 2 s .c o m*/ b.channel(NioSocketChannel.class); b.handler(initHandler); Channel ch = null; try { ch = b.connect(host, port).syncUninterruptibly().channel(); THttp2ClientHandler handler = initHandler.THttp2ClientHandler; // Wait until HTTP/2 upgrade is finished. assertTrue(handler.settingsPromise.await(5, TimeUnit.SECONDS)); handler.settingsPromise.get(); // Send a Thrift request. FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, path, Unpooled.wrappedBuffer(out.getArray(), 0, out.length())); request.headers().add(HttpHeaderNames.HOST, host); request.headers().set(ExtensionHeaderNames.SCHEME.text(), uri.getScheme()); ch.writeAndFlush(request).sync(); // Wait until the Thrift response is received. assertTrue(handler.responsePromise.await(5, TimeUnit.SECONDS)); ByteBuf response = handler.responsePromise.get(); // Pass the received Thrift response to the Thrift client. final byte[] array = new byte[response.readableBytes()]; response.readBytes(array); in = new TMemoryInputTransport(array); response.release(); } catch (Exception e) { throw new TTransportException(TTransportException.UNKNOWN, e); } finally { if (ch != null) { ch.close(); } } }
From source file:com.myftpserver.handler.SendBinaryFileHandler.java
License:Apache License
@Override public void startToSend(ChannelHandlerContext ctx) throws Exception { if (fs.getDownloadFile().length() > 0L) { downloadFile = new RandomAccessFile(fs.getDownloadFile(), "r"); fc = downloadFile.getChannel();//from ww w. ja v a2 s . co m byteRead = fc.read(buffer); ctx.writeAndFlush(Unpooled.wrappedBuffer(buffer.array(), 0, byteRead)); } else closeChannel(ctx); }
From source file:com.myftpserver.handler.SendBinaryFileHandler.java
License:Apache License
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { if (isCompleted) { fc.close();/* w w w .j av a2 s. co m*/ downloadFile.close(); closeChannel(ctx); } else { if (fc.position() == downloadFile.length()) { isCompleted = true; } else { if (ctx.channel().isWritable()) { buffer.clear(); byteRead = fc.read(buffer); if (byteRead > 0) { ctx.writeAndFlush(Unpooled.wrappedBuffer(buffer.array(), 0, byteRead)); } else isCompleted = true; } } } }
From source file:com.scurrilous.circe.checksum.ChecksumTest.java
License:Apache License
@Test public void testCrc32cValueIncremental() { final byte[] bytes = "Some String".getBytes(); int checksum = Crc32cIntChecksum.CRC32C_HASH.calculate(bytes, 0, bytes.length); assertEquals(608512271, checksum);//from w w w.j ava 2 s .c o m checksum = Crc32cIntChecksum.CRC32C_HASH.calculate(bytes, 0, 1); for (int i = 1; i < bytes.length; i++) { checksum = Crc32cIntChecksum.CRC32C_HASH.resume(checksum, bytes, i, 1); } assertEquals(608512271, checksum); checksum = Crc32cIntChecksum.CRC32C_HASH.calculate(bytes, 0, 4); checksum = Crc32cIntChecksum.CRC32C_HASH.resume(checksum, bytes, 4, 7); assertEquals(608512271, checksum); ByteBuf buffer = Unpooled.wrappedBuffer(bytes, 0, 4); checksum = Crc32cIntChecksum.computeChecksum(buffer); checksum = Crc32cIntChecksum.resumeChecksum(checksum, Unpooled.wrappedBuffer(bytes, 4, bytes.length - 4)); assertEquals(608512271, checksum); }