Package io.netty.buffer

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


            byte[] bytes;
            int offset;
            int len;
            if (buffer.hasArray()) {
                bytes = buffer.array();
                offset = buffer.arrayOffset() + buffer.readerIndex();
                len = buffer.readableBytes();
            } else {
                bytes = readBytes(buffer);
                offset = 0;
                len = bytes.length;
View Full Code Here


            byte[] input = CBUtil.readRawBytes(frame.body);
            ByteBuf output = CBUtil.onHeapAllocator.buffer(Snappy.maxCompressedLength(input.length));

            try
            {
                int written = Snappy.compress(input, 0, input.length, output.array(), output.arrayOffset());
                output.writerIndex(written);
            }
            catch (final Throwable e)
            {
                output.release();
View Full Code Here

            ByteBuf output = CBUtil.onHeapAllocator.buffer(Snappy.uncompressedLength(input));

            try
            {
                int size = Snappy.uncompress(input, 0, input.length, output.array(), output.arrayOffset());
                output.writerIndex(size);
            }
            catch (final Throwable e)
            {
                output.release();
View Full Code Here

            int maxCompressedLength = compressor.maxCompressedLength(input.length);
            ByteBuf outputBuf = CBUtil.onHeapAllocator.buffer(INTEGER_BYTES + maxCompressedLength);

            byte[] output = outputBuf.array();
            int outputOffset = outputBuf.arrayOffset();

            output[outputOffset + 0] = (byte) (input.length >>> 24);
            output[outputOffset + 1] = (byte) (input.length >>> 16);
            output[outputOffset + 2] = (byte) (input.length >>>  8);
            output[outputOffset + 3] = (byte) (input.length);
View Full Code Here

            ByteBuf output = CBUtil.onHeapAllocator.buffer(uncompressedLength);

            try
            {
                int read = decompressor.decompress(input, INTEGER_BYTES, output.array(), output.arrayOffset(), uncompressedLength);
                if (read != input.length - INTEGER_BYTES)
                    throw new IOException("Compressed lengths mismatch");

                output.writerIndex(uncompressedLength);
View Full Code Here

         byte[] bytes;
         int offset;
         int len;
         if (buffer.hasArray()) {
             bytes = buffer.array();
             offset = buffer.arrayOffset() + buffer.readerIndex();
             len = buffer.readableBytes();
         } else {
             bytes = readBytes(buffer);
             offset = 0;
             len = bytes.length;
View Full Code Here

            int oldNextOutIndex = z.next_out_index;

            int maxOutputLength = (int) Math.ceil(z.next_in.length * 1.001) + 12;
            out = alloc.heapBuffer(maxOutputLength);
            z.next_out = out.array();
            z.next_out_index = out.arrayOffset() + out.writerIndex();
            z.avail_out = maxOutputLength;

            int resultCode;
            try {
                resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
View Full Code Here

        int packetSize = config().getReceivePacketSize();
        ByteBuf buffer = alloc().heapBuffer(packetSize);
        boolean free = true;

        try {
            tmpPacket.setData(buffer.array(), buffer.arrayOffset(), packetSize);
            socket.receive(tmpPacket);

            InetSocketAddress remoteAddr = (InetSocketAddress) tmpPacket.getSocketAddress();
            if (remoteAddr == null) {
                remoteAddr = remoteAddress();
View Full Code Here

            InetSocketAddress remote = p.remoteAddress();
            if (remote != null) {
                tmpPacket.setSocketAddress(remote);
            }
            if (data.hasArray()) {
                tmpPacket.setData(data.array(), data.arrayOffset() + data.readerIndex(), length);
            } else {
                byte[] tmp = new byte[length];
                data.getBytes(data.readerIndex(), tmp);
                tmpPacket.setData(tmp);
            }
View Full Code Here

            byte[] input = CBUtil.readRawBytes(frame.body);
            ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.maxCompressedLength(input.length));

            try
            {
                int written = Snappy.compress(input, 0, input.length, output.array(), output.arrayOffset());
                output.writerIndex(written);
            }
            catch (final Throwable e)
            {
                output.release();
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.