List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:uk.co.thinkofdeath.prismarine.network.CompressionCodec.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { MCByteBuf buf = new MCByteBuf(in); int size = buf.readVarInt(); if (size == 0) { out.add(buf.readBytes(buf.readableBytes())); } else {/*from www.j a v a 2s . co m*/ CompressionInfo ci = info.get(); if (ci.decompBuffer.length < in.readableBytes()) { ci.decompBuffer = new byte[in.readableBytes()]; } int count = in.readableBytes(); in.readBytes(ci.decompBuffer, 0, count); ci.inflater.setInput(ci.decompBuffer, 0, count); // Use heap buffers so we can just access the internal array ByteBuf oBuf = ctx.alloc().heapBuffer(size); oBuf.writerIndex(ci.inflater.inflate(oBuf.array(), oBuf.arrayOffset(), size)); out.add(oBuf); ci.inflater.reset(); } }
From source file:websocketclient.WebSocketClientHandler.java
License:Apache License
public void sendBinary(short msgId, ByteBuf buf, Channel ch) { //?(int)+??(short)+?(byte[]) int len = buf.array().length + 7; ByteBuf byteBuf = Unpooled.buffer(len); byteBuf.writeByte(43);//head flag byteBuf.writeInt(len);//from www. j a v a 2 s . c o m byteBuf.writeShort(msgId); byteBuf.writeByte(0); byteBuf.writeBytes(buf); ch.writeAndFlush(new BinaryWebSocketFrame(byteBuf)); }