Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.copy()


    byte discriminator = (byte) packets.indexOf(cl);
    encodedData.writeByte(discriminator);
    //Get the packet class to encode our packet
    msg.encodeInto(ctx, encodedData);
    //Convert our packet into a Forge packet to get it through the Netty system
    FMLProxyPacket proxyPacket = new FMLProxyPacket(encodedData.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    //Add our packet to the outgoing packet queue
    out.add(proxyPacket);
  }

  @Override
View Full Code Here


      throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
    }
    byte discriminator = (byte) this.packets.indexOf(packetClass);
    buffer.writeByte(discriminator);
    msg.encodeInto(ctx, buffer);
    FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    out.add(proxyPacket);
  }

  @Override
  protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
View Full Code Here

  private static FMLProxyPacket toFMLPacket(ModernPacket msg, String channel) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    buffer.writeShort(msg.getId());
    buffer.writeInt(msg.getDebugId());
    msg.writeData(new LPDataOutputStream(buffer));
    return new FMLProxyPacket(buffer.copy(), channel);
  }

  @Override
  protected final void encode(ChannelHandlerContext ctx, ModernPacket msg, List<Object> out) throws Exception
  {
View Full Code Here

        ByteBuf data = Unpooled.wrappedBuffer(bytes);
        ByteBuf deflatedData = Unpooled.wrappedBuffer(gzip(bytes));

        EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
        try {
            chDecoderGZip.writeInbound(deflatedData.copy());
            assertTrue(chDecoderGZip.finish());
            ByteBuf buf = chDecoderGZip.readInbound();
            assertEquals(buf, data);
            assertNull(chDecoderGZip.readInbound());
            data.release();
View Full Code Here

    public void frameLargerThanMaxFrameSizeShouldBeSplit() throws Http2Exception {
        when(frameWriterSizePolicy.maxFrameSize()).thenReturn(3);

        final ByteBuf data = dummyData(5, 0);
        try {
            send(STREAM_A, data.copy(), 5);

            verifyWrite(STREAM_A, data.slice(0, 3), 0);
            verifyWrite(STREAM_A, data.slice(3, 2), 1);
            verifyWrite(STREAM_A, Unpooled.EMPTY_BUFFER, 3);
            verifyWrite(STREAM_A, Unpooled.EMPTY_BUFFER, 1);
View Full Code Here

    public void testStreamStartIsOnlyWrittenOnce() throws Exception {
        ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
            'n', 'e', 't', 't', 'y'
        });

        channel.writeOutbound(in.copy());
        in.readerIndex(0); // rewind the buffer to write the same data
        channel.writeOutbound(in.copy());
        assertTrue(channel.finish());

        ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
View Full Code Here

            'n', 'e', 't', 't', 'y'
        });

        channel.writeOutbound(in.copy());
        in.readerIndex(0); // rewind the buffer to write the same data
        channel.writeOutbound(in.copy());
        assertTrue(channel.finish());

        ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
            (byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
             0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
View Full Code Here

        MemoryFileUpload upload = new MemoryFileUpload(getName(), getFilename(), getContentType(),
                getContentTransferEncoding(), getCharset(), size);
        ByteBuf buf = content();
        if (buf != null) {
            try {
                upload.setContent(buf.copy());
                return upload;
            } catch (IOException e) {
                throw new ChannelException(e);
            }
        }
View Full Code Here

        default:
            throw new IllegalArgumentException("unknown version");
        }

        final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(autoRead);
        final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames.copy(), autoRead);

        sb.childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel channel) throws Exception {
                channel.pipeline().addLast(
View Full Code Here

        // Maybe we should better not copy here for performance reasons but this will need
        // more care by the caller to release the content in a correct manner later
        // So maybe something to optimize on a later stage
        ByteBuf buf = content.content();
        if (undecodedChunk == null) {
            undecodedChunk = buf.copy();
        } else {
            undecodedChunk.writeBytes(buf);
        }
        if (content instanceof LastHttpContent) {
            isLastChunk = true;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.