Package io.netty.buffer

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


        }

        log.debug("wrote reply: {}", reply);

        // now set the length
        final int writerIndex = out.writerIndex();
        out.setInt(0, writerIndex);
    }
}
View Full Code Here


    protected int doReadMessages(MessageBuf<Object> buf) throws Exception {
        SctpChannel ch = javaChannel();
        ByteBuf buffer = alloc().directBuffer(config().getReceiveBufferSize());
        boolean free = true;
        try {
            ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
            MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
            if (messageInfo == null) {
                return 0;
            }
View Full Code Here

            if (messageInfo == null) {
                return 0;
            }

            data.flip();
            buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
            free = false;
            return 1;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
            return -1;
View Full Code Here

            if (messageInfo == null) {
                return 0;
            }

            data.flip();
            buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
            free = false;
            return 1;
        } catch (Throwable cause) {
            PlatformDependent.throwException(cause);
            return -1;
View Full Code Here

                                    "an inbound handler whose buffer is full must consume at " +
                                            "least one byte.");
                        }
                    }
                } else {
                    final int writerIndex = byteBuf.writerIndex();
                    if (writerIndex + available > maxCapacity) {
                        byteBuf.capacity(maxCapacity);
                    } else {
                        byteBuf.ensureWritable(available);
                    }
View Full Code Here

                    // Set the writerIndex of the buffer correctly to the
                    // current writerIndex + read amount of bytes.
                    //
                    // This is needed as the ByteBuffer and the ByteBuf does not share
                    // each others index
                    byteBuf.writerIndex(byteBuf.writerIndex() + localReadAmount);

                    read = true;
                } else if (localReadAmount < 0) {
                    closed = true;
                }
View Full Code Here

            int random = (int) (Math.random() * Integer.MAX_VALUE);
            mask = ByteBuffer.allocate(4).putInt(random).array();
            out.writeBytes(mask);

            int counter = 0;
            for (int i = data.readerIndex(); i < data.writerIndex(); i ++) {
                byte byteData = data.getByte(i);
                out.writeByte(byteData ^ mask[counter++ % 4]);
            }
        } else {
            out.writeBytes(data, data.readerIndex(), data.readableBytes());
View Full Code Here

            for (SelectionKey ignored : reableKeys) {
                ByteBuf buffer = alloc().directBuffer(config().getReceiveBufferSize());
                boolean free = true;

                try {
                    ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());
                    MessageInfo messageInfo = ch.receive(data, null, notificationHandler);
                    if (messageInfo == null) {
                        return readMessages;
                    }
View Full Code Here

                    if (messageInfo == null) {
                        return readMessages;
                    }

                    data.flip();
                    buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
                    free = false;
                    readMessages ++;
                } catch (Throwable cause) {
                    PlatformDependent.throwException(cause);
                finally {
View Full Code Here

                    if (messageInfo == null) {
                        return readMessages;
                    }

                    data.flip();
                    buf.add(new SctpMessage(messageInfo, buffer.writerIndex(buffer.writerIndex() + data.remaining())));
                    free = false;
                    readMessages ++;
                } catch (Throwable cause) {
                    PlatformDependent.throwException(cause);
                finally {
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.