Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf


        return true;

    }

    protected ByteBuf readBody() {
        ByteBuf data = null;
        if (this.buf.readableBytes() <= this.length) {
            data = this.buf.readSlice(this.buf.readableBytes());
            this.length -= data.readableBytes();
        } else {
            data = this.buf.readSlice(this.length);
            this.length = 0;
        }
View Full Code Here


        this.type = Type.INPUT;
    }

    public void writeUtf8String(String data, int fd) {
        ByteBuf buffer = this.channelFuture.channel().alloc().buffer();
        buffer.writeBytes(data.getBytes(StandardCharsets.UTF_8));
        this.channelFuture.channel().writeAndFlush(new IPCRecord(buffer, fd));
    }
View Full Code Here

    public static ByteBuf extract(JSObject object) {
        return ((NettyExternalIndexedData)object.getExternalIndexedData()).buffer();
    }

    public static byte[] extractByteArray(JSObject object) {
        ByteBuf buf = extract( object );
        byte[] bytes = new byte[ bufLen( object ) ];
        buf.getBytes( buf.readerIndex(), bytes );
        return bytes;
    }
View Full Code Here

        if ( val instanceof Number ) {
            byteVal = ((Number) val).intValue() & 0xFF;
        } else if ( val instanceof String && ! ((String) val).isEmpty() ) {
            byteVal = ((String) val).charAt(0);
        }
        ByteBuf b = extract(obj);
        for ( int i = offset; i < end; ++i ) {
            b.setByte( i, byteVal );
        }
        b.writerIndex( Math.max( b.writerIndex(), offset + end ) );
        return obj;
    }
View Full Code Here

        return obj;
    }

    public static long copy(JSObject src, JSObject target, int targetStart, int sourceStart, int sourceEnd) {

        ByteBuf srcBuf = extract(src);
        ByteBuf targetBuf = extract(target);

        int origWriter = targetBuf.writerIndex();

        targetBuf.writerIndex( targetStart );

        int len = sourceEnd - sourceStart;

        len = Math.min( len, bufLen( target ) - targetStart );

        targetBuf.writeBytes(srcBuf, sourceStart, len);
        targetBuf.writerIndex(Math.max(targetBuf.writerIndex(), origWriter));

        return len;
    }
View Full Code Here

    // ----------------------------------------
    // utf8
    // ----------------------------------------

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

        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return new long[] { str.length(), len };
    }

    public static String utf8Slice(JSObject object, int start, int end) {
        ByteBuf b = extract( object );
        return b.toString( start, (end-start), UTF8 );
    }
View Full Code Here

    // ----------------------------------------
    // ascii
    // ----------------------------------------

    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

        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }

    public static String asciiSlice(JSObject object, int start, int end) {
        ByteBuf b = extract( object );
        return b.toString( start, (end-start), ASCII );
    }
View Full Code Here

    // ----------------------------------------
    // ucs2
    // ----------------------------------------

    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

TOP

Related Classes of io.netty.buffer.ByteBuf

Copyright © 2018 www.massapicom. 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.