Package io.netty.buffer

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


    public static long asciiWrite(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = str.getBytes( ASCII );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }
View Full Code Here


    public static long ucs2Write(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = str.getBytes( UCS2 );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }
View Full Code Here

    public static long hexWrite(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = Hex.decode(str);
        b.writerIndex( offset );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }
View Full Code Here

    public static long base64Write(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = Base64.decode(str);
        b.writerIndex( offset );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes(bytes, 0, len);
        b.writerIndex(Math.max(b.writerIndex(), origWriter));
        return len;
    }
View Full Code Here

    public static long binaryWrite(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = str.getBytes( BINARY );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }
View Full Code Here

                        if (data.hasMemoryAddress()) {
                            // has a memory address so use optimized call
                            remoteAddress = Native.recvFromAddress(
                                    fd, data.memoryAddress(), writerIndex, data.capacity());
                        } else {
                            ByteBuffer nioData = data.internalNioBuffer(writerIndex, data.writableBytes());
                            remoteAddress = Native.recvFrom(
                                    fd, nioData, nioData.position(), nioData.limit());
                        }

                        if (remoteAddress == null) {
View Full Code Here

                int totalReadAmount = 0;
                for (;;) {
                    // we use a direct buffer here as the native implementations only be able
                    // to handle direct buffers.
                    byteBuf = allocHandle.allocate(allocator);
                    int writable = byteBuf.writableBytes();
                    int localReadAmount = doReadBytes(byteBuf);
                    if (localReadAmount <= 0) {
                        // not was read release the buffer
                        byteBuf.release();
                        close = localReadAmount < 0;
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

            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

    protected int doReadMessages(MessageBuf<Object> buf) throws Exception {
        DatagramChannel ch = javaChannel();
        ByteBuf buffer = alloc().directBuffer(config().getReceivePacketSize());
        boolean free = true;
        try {
            ByteBuffer data = buffer.nioBuffer(buffer.writerIndex(), buffer.writableBytes());

            InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(data);
            if (remoteAddress == null) {
                return 0;
            }
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.