List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer(int initialCapacity)
From source file:alluxio.network.protocol.databuffer.DataNettyBufferTest.java
License:Apache License
/** * Sets up the buffer before a test runs. */ @Before public final void before() { mBuffer = Unpooled.buffer(LENGTH); }
From source file:alluxio.network.protocol.databuffer.DataNettyBufferTest.java
License:Apache License
/** * Tests that an exception is thrown when two NIO buffers are used. *//*w ww .ja v a 2 s .c om*/ @Test public void singleNioBufferCheckFailed() { mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage("Number of nioBuffers of this bytebuf is 2 (1 expected)."); releaseBuffer(); // not using the default ByteBuf given in Before() // creating a CompositeByteBuf with 2 NIO buffers mBuffer = Unpooled.compositeBuffer(); ((CompositeByteBuf) mBuffer).addComponent(Unpooled.buffer(LENGTH)); ((CompositeByteBuf) mBuffer).addComponent(Unpooled.buffer(LENGTH)); new DataNettyBuffer(mBuffer, LENGTH); }
From source file:appeng.core.sync.packets.PacketCompressedNBT.java
License:Open Source License
public PacketCompressedNBT(final NBTTagCompound din) throws IOException { this.data = Unpooled.buffer(2048); this.data.writeInt(this.getPacketID()); this.in = din; this.compressFrame = new GZIPOutputStream(new OutputStream() { @Override/*from w ww .jav a2 s . c o m*/ public void write(final int value) throws IOException { PacketCompressedNBT.this.data.writeByte(value); } }); CompressedStreamTools.write(din, new DataOutputStream(this.compressFrame)); this.compressFrame.close(); this.configureWrite(this.data); }
From source file:appeng.core.sync.packets.PacketMEInventoryUpdate.java
License:Open Source License
public PacketMEInventoryUpdate(final ByteBuf stream) throws IOException { this.data = null; this.compressFrame = null; this.list = new LinkedList<IAEItemStack>(); this.ref = stream.readByte(); // int originalBytes = stream.readableBytes(); final GZIPInputStream gzReader = new GZIPInputStream(new InputStream() { @Override/* w ww.j a v a2 s. c o m*/ public int read() throws IOException { if (stream.readableBytes() <= 0) { return -1; } return stream.readByte() & STREAM_MASK; } }); final ByteBuf uncompressed = Unpooled.buffer(stream.readableBytes()); final byte[] tmp = new byte[TEMP_BUFFER_SIZE]; while (gzReader.available() != 0) { final int bytes = gzReader.read(tmp); if (bytes > 0) { uncompressed.writeBytes(tmp, 0, bytes); } } gzReader.close(); // int uncompressedBytes = uncompressed.readableBytes(); // AELog.info( "Receiver: " + originalBytes + " -> " + uncompressedBytes ); while (uncompressed.readableBytes() > 0) { this.list.add(AEItemStack.loadItemStackFromPacket(uncompressed)); } this.empty = this.list.isEmpty(); }
From source file:appeng.core.sync.packets.PacketMEInventoryUpdate.java
License:Open Source License
public PacketMEInventoryUpdate(final byte ref) throws IOException { this.ref = ref; this.data = Unpooled.buffer(OPERATION_BYTE_LIMIT); this.data.writeInt(this.getPacketID()); this.data.writeByte(this.ref); this.compressFrame = new GZIPOutputStream(new OutputStream() { @Override/*from w ww. jav a 2 s .c o m*/ public void write(final int value) throws IOException { PacketMEInventoryUpdate.this.data.writeByte(value); } }); this.list = null; }
From source file:appeng.core.sync.packets.PacketMEInventoryUpdate.java
License:Open Source License
public void appendItem(final IAEItemStack is) throws IOException, BufferOverflowException { final ByteBuf tmp = Unpooled.buffer(OPERATION_BYTE_LIMIT); is.writeToPacket(tmp);/*from w ww .j a va2s . co m*/ this.compressFrame.flush(); if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) { throw new BufferOverflowException(); } else { this.writtenBytes += tmp.readableBytes(); this.compressFrame.write(tmp.array(), 0, tmp.readableBytes()); this.empty = false; } }
From source file:basic.TimeClientHandler.java
License:Apache License
/** * Creates a client-side handler.//from w w w .j a v a2 s .c om */ public TimeClientHandler() { byte[] req = "QUERY TIME ORDER".getBytes(); firstMessage = Unpooled.buffer(req.length); firstMessage.writeBytes(req); }
From source file:book.netty.n2defualtC4P2.TimeClientHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) { ByteBuf message = null;/*from www .ja va 2 s .c o m*/ for (int i = 0; i < 100; i++) { message = Unpooled.buffer(req.length); message.writeBytes(req); ctx.writeAndFlush(message); } }
From source file:buildcraft.core.network.PacketRPC.java
License:Minecraft Mod Public
@Override public void readData(ByteBuf data) { id = data.readInt(); int length = data.readInt(); contents = Unpooled.buffer(length); data.readBytes(contents, length); }
From source file:cat.tbq.hospital.nio.echoExample.EchoClientHandler.java
License:Apache License
/** * Creates a client-side handler. */ public EchoClientHandler() { firstMessage = Unpooled.buffer(10); firstMessage.writeBytes("abcdefghij".getBytes()); }