List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract ByteBuf writeBytes(ByteBuffer src);
From source file:Http2ClientConnectionHandler.java
License:Apache License
@Override public void onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream, boolean endOfSegment) throws Http2Exception { // Copy the data into the buffer. int available = data.readableBytes(); if (collectedData == null) { collectedData = ctx().alloc().buffer(available); collectedData.writeBytes(data, data.readerIndex(), data.readableBytes()); } else {//w w w. j a v a2s .c om // Expand the buffer ByteBuf newBuffer = ctx().alloc().buffer(collectedData.readableBytes() + available); newBuffer.writeBytes(collectedData); newBuffer.writeBytes(data); collectedData.release(); collectedData = newBuffer; } // If it's the last frame, print the complete message. if (endOfStream) { // System.out.println("Received message: " + collectedData.toString(CharsetUtil.UTF_8)); final OutstandingRequest outstandingRequest = outstanding.remove(streamId); outstandingRequest.finish(collectedData); // Free the data buffer. collectedData.release(); collectedData = null; } }
From source file:HelloWorldHttp1Handler.java
License:Apache License
@Override public void messageReceived(ChannelHandlerContext ctx, HttpRequest req) throws Exception { if (HttpHeaderUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE)); }/* w w w. j a v a 2 s . c o m*/ boolean keepAlive = HttpHeaderUtil.isKeepAlive(req); ByteBuf content = ctx.alloc().buffer(); content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate()); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content); response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8"); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); if (!keepAlive) { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } else { response.headers().set(CONNECTION, Values.KEEP_ALIVE); ctx.writeAndFlush(response); } }
From source file:alluxio.network.protocol.RPCProtoMessage.java
License:Apache License
@Override public void encode(ByteBuf out) { out.writeInt(mMessageEncoded.length); out.writeBytes(mMessageEncoded); }
From source file:alluxio.worker.block.io.MockBlockReader.java
License:Apache License
@Override public int transferTo(ByteBuf buf) throws IOException { int remaining = buf.readableBytes(); return buf.writeBytes(mBytes).readableBytes() - remaining; }
From source file:appeng.core.sync.packets.PacketJEIRecipe.java
License:Open Source License
public PacketJEIRecipe(final NBTTagCompound recipe) throws IOException { final ByteBuf data = Unpooled.buffer(); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final DataOutputStream outputStream = new DataOutputStream(bytes); data.writeInt(this.getPacketID()); CompressedStreamTools.writeCompressed(recipe, outputStream); data.writeBytes(bytes.toByteArray()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketNEIRecipe.java
License:Open Source License
public PacketNEIRecipe(final NBTTagCompound recipe) throws IOException { final ByteBuf data = Unpooled.buffer(); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final DataOutputStream outputStream = new DataOutputStream(bytes); data.writeInt(this.getPacketID()); CompressedStreamTools.writeCompressed(recipe, outputStream); data.writeBytes(bytes.toByteArray()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketPartialItem.java
License:Open Source License
public PacketPartialItem(final int page, final int maxPages, final byte[] buf) { final ByteBuf data = Unpooled.buffer(); this.pageNum = (short) (page | (maxPages << 8)); this.data = buf; data.writeInt(this.getPacketID()); data.writeShort(this.pageNum); data.writeBytes(buf); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketValueConfig.java
License:Open Source License
public PacketValueConfig(final String name, final String value) throws IOException { this.Name = name; this.Value = value; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(bos); dos.writeUTF(name);/*from ww w. ja v a2s . c o m*/ dos.writeUTF(value); // dos.close(); data.writeBytes(bos.toByteArray()); this.configureWrite(data); }
From source file:appeng.util.item.AEFluidStack.java
License:Open Source License
@Override void writeIdentity(final ByteBuf i) throws IOException { final byte[] name = this.fluid.getName().getBytes("UTF-8"); i.writeByte((byte) name.length); i.writeBytes(name); }
From source file:appeng.util.item.AEFluidStack.java
License:Open Source License
@Override void readNBT(final ByteBuf i) throws IOException { if (this.hasTagCompound()) { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final DataOutputStream data = new DataOutputStream(bytes); CompressedStreamTools.write((NBTTagCompound) this.tagCompound, data); final byte[] tagBytes = bytes.toByteArray(); final int size = tagBytes.length; i.writeInt(size);//w ww .j a va2 s.c o m i.writeBytes(tagBytes); } }