Package io.netty.buffer

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


            ByteBuf frame =  (ByteBuf) super.decode(ctx, buffer);
            if (frame == null) {
                return null;
            }
            int index = frame.indexOf(frame.readerIndex(), frame.writerIndex(), (byte) ' ');
            return new Cmd(frame.slice(frame.readerIndex(), index), frame.slice(index +1, frame.writerIndex()));
        }
    }

    public static final class CmdHandler extends SimpleChannelInboundHandler<Cmd> {
        @Override
View Full Code Here


    decodeAndVerify(ch, buf, envelopes);
    Assert.assertEquals(refCount - 1, buf.refCnt());

    // 2. random slices
    buf.readerIndex(0);
    ByteBuf[] slices = randomSlices(buf);

    ch.writeInbound(slices);

    for (ByteBuf slice : slices) {
View Full Code Here

          List<ByteBuf> slice = new ArrayList<ByteBuf>(components.size());

          // The first component
          Component firstC = components.get(componentId);
          ByteBuf first = firstC.buf.duplicate();
          first.readerIndex(offset - firstC.offset);

          ByteBuf buf = first;
          int bytesToSlice = length;
          do {
              int readableBytes = buf.readableBytes();
View Full Code Here

          int bytesToSlice = length;
          do {
              int readableBytes = buf.readableBytes();
              if (bytesToSlice <= readableBytes) {
                  // Last component
                  buf.writerIndex(buf.readerIndex() + bytesToSlice);
                  slice.add(buf);
                  break;
              } else {
                  // Not the last component
                  slice.add(buf);
View Full Code Here

        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[] {
            (byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
View Full Code Here

            data.setContent(new ByteArrayInputStream(bytes));

            // Validate stored data.
            ByteBuf buffer = data.getByteBuf();

            assertEquals(0, buffer.readerIndex());
            assertEquals(bytes.length, buffer.writerIndex());
            assertArrayEquals(bytes, Arrays.copyOf(buffer.array(), bytes.length));
        }
    }
View Full Code Here

            if (contentLen != INADDRSZ4 && contentLen != INADDRSZ6) {
                continue;
            }

            final byte[] addrBytes = new byte[contentLen];
            content.getBytes(content.readerIndex(), addrBytes);

            try {
                InetAddress resolved = InetAddress.getByAddress(hostname, addrBytes);
                if (resolvedAddresses == null) {
                    resolvedAddresses = new ArrayList<InetAddress>();
View Full Code Here

                assert writtenBytes == 0;
                break;
            }

            final ByteBuf buf = (ByteBuf) msg;
            final int readerIndex = buf.readerIndex();
            final int readableBytes = buf.writerIndex() - readerIndex;

            if (readableBytes <= writtenBytes) {
                if (writtenBytes != 0) {
                    progress(readableBytes);
View Full Code Here

                    writtenBytes -= readableBytes;
                }
                remove();
            } else { // readableBytes > writtenBytes
                if (writtenBytes != 0) {
                    buf.readerIndex(readerIndex + (int) writtenBytes);
                    progress(writtenBytes);
                }
                break;
            }
        }
View Full Code Here

        ByteBuffer[] nioBuffers = NIO_BUFFERS.get(threadLocalMap);
        Entry entry = flushedEntry;
        while (isFlushedEntry(entry) && entry.msg instanceof ByteBuf) {
            if (!entry.cancelled) {
                ByteBuf buf = (ByteBuf) entry.msg;
                final int readerIndex = buf.readerIndex();
                final int readableBytes = buf.writerIndex() - readerIndex;

                if (readableBytes > 0) {
                    nioBufferSize += readableBytes;
                    int count = entry.count;
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.