Package net.gleamynode.netty.array

Examples of net.gleamynode.netty.array.ByteArray


            PipeContext<ChannelEvent> ctx, Channel channel, ByteArrayBuffer buffer) throws Exception {
        // Try all delimiters.
        for (ByteArray delim: delimiters) {
            int delimIndex = indexOf(buffer, delim);
            if (delimIndex > buffer.firstIndex()) {
                ByteArray frame = buffer.read(delimIndex - buffer.firstIndex());
                if (frame.length() > maxFrameLength) {
                    fail();
                }
                buffer.skip(delim.length());
                return frame;
            } else if (delimIndex == buffer.firstIndex()) {
View Full Code Here


        if (readBytes > 0) {
            // Update the predictor.
            predictor.previousReceiveBufferSize(readBytes);

            // Fire the event.
            ByteArray array;
            if (readBytes == buf.capacity()) {
                array = new HeapByteArray(buf.array());
            } else {
                array = new StaticPartialByteArray(buf.array(), 0, readBytes);
            }
View Full Code Here

                    channel.currentWriteEvent = channel.writeBuffer.poll();
                    channel.currentWriteIndex =
                        ((ByteArray) channel.currentWriteEvent.getMessage()).firstIndex();
                }

                ByteArray a = (ByteArray) channel.currentWriteEvent.getMessage();
                int localWrittenBytes = 0;
                try {
                    for (int i = channel.getConfig().getWriteSpinCount(); i > 0; i --) {
                        localWrittenBytes = a.copyTo(
                            channel.socket,
                            channel.currentWriteIndex,
                            Math.min(maxWrittenBytes - writtenBytes, a.length() - (channel.currentWriteIndex - a.firstIndex())));
                        if (localWrittenBytes != 0) {
                            break;
                        }
                    }
                } catch (Throwable t) {
                    channel.currentWriteEvent.getFuture().setFailure(t);
                    fireExceptionCaught(channel, t);
                }

                writtenBytes += localWrittenBytes;
                channel.currentWriteIndex += localWrittenBytes;
                if (channel.currentWriteIndex == a.endIndex()) {
                    channel.currentWriteEvent.getFuture().setSuccess();
                    channel.currentWriteEvent = null;
                } else if (localWrittenBytes == 0 || writtenBytes < maxWrittenBytes) {
                    addOpWrite = true;
                    break;
View Full Code Here

        if (!(m instanceof ByteArray)) {
            ctx.sendUpstream(e);
            return;
        }

        ByteArray input = (ByteArray) m;
        if (input.empty()) {
            return;
        }

        ReplayableByteArrayBuffer cumulation = this.cumulation;

        // Avoid CompositeByteArray index overflow.
        if (Integer.MAX_VALUE - cumulation.endIndex() < input.length()) {
            ReplayableByteArrayBuffer newCumulation = new ReplayableByteArrayBuffer();
            for (ByteArray component: cumulation) {
                newCumulation.unwrap().write(component);
            }
            this.cumulation = cumulation = newCumulation;
View Full Code Here

        if (!(e.getMessage() instanceof ByteArray)) {
            context.sendUpstream(element);
            return;
        }

        ByteArray src = (ByteArray) e.getMessage();
        byte[] dst = new byte[src.length()];
        src.get(src.firstIndex(), dst);
        ChannelUpstream.fireMessageReceived(context, e.getChannel(), new String(dst, charsetName));
    }
View Full Code Here

        firstIndex = 0;
    }

    @Override
    public ByteArray read() {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
        } else if (empty()) {
            rewind();
            return null;
        } else {
            a = record(super.read());
        }

        firstIndex += a.length();
        return a;
    }
View Full Code Here

        return a;
    }

    @Override
    public ByteArray read(ByteArrayIndexFinder endIndexFinder) {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
        } else if (super.indexOf(0, endIndexFinder) == NOT_FOUND) {
            rewind();
            return null;
        } else {
            a = record(super.read(endIndexFinder));
        }

        firstIndex += a.length();
        return a;
    }
View Full Code Here

        return a;
    }

    @Override
    public ByteArray read(int length) {
        ByteArray a;
        if (isReplaying()) {
            a = (ByteArray) replay();
            if (a.length() != length) {
                throw new IllegalStateException("mismatching request");
            }
        } else if (length > super.length()) {
            rewind();
            return null;
View Full Code Here

    }

    @Override
    public void get(int index, ByteArray dst, int dstIndex, int length) {
        if (isReplaying()) {
            ByteArray src = (ByteArray) replay();
            if (src.length() != length) {
                throw new IllegalStateException("mismatching request");
            }
            src.get(0, dst, dstIndex, length);
        } else if (index < super.firstIndex() || dstIndex + length > dst.endIndex()) {
            throw new NoSuchElementException();
        } else if (index + length > super.endIndex()) {
            rewind();
        } else {
            ByteArray src = new HeapByteArray(length);
            super.get(index, src, 0, length);
            src.get(0, dst, dstIndex, length);
            record(src);
        }
    }
View Full Code Here

            context.sendDownstream(element);
            return;
        }

        // Otherwise, all messages are encrypted.
        ByteArray msg = (ByteArray) e.getMessage();
        PendingWrite pendingWrite =
            new PendingWrite(element.getFuture(), msg.getByteBuffer());
        synchronized (pendingUnencryptedWrites) {
            pendingUnencryptedWrites.offer(pendingWrite);
        }

        wrap(context, element.getChannel());
View Full Code Here

TOP

Related Classes of net.gleamynode.netty.array.ByteArray

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.