Package io.netty.buffer

Examples of io.netty.buffer.ChannelBuffer


        return buffer.readBytes(buffer.readableBytes());
    }

    private ChannelBuffer buffer(ChannelHandlerContext ctx) throws Exception {
        ChannelBuffer buf = buffer.get();
        if (buf == null) {
            ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
            buf = ChannelBuffers.dynamicBuffer(factory);
            if (buffer.compareAndSet(null, buf)) {
                boolean success = false;
View Full Code Here


    /**
     * Stores the internal cumulative buffer's reader position.
     */
    protected void checkpoint() {
        ChannelBuffer cumulation = this.cumulation;
        if (cumulation != null) {
            checkpoint = cumulation.readerIndex();
        } else {
            checkpoint = -1; // buffer not available (already cleaned up)
        }
    }
View Full Code Here

     * Returns the internal cumulative buffer of this decoder.  You usually
     * do not need to access the internal buffer directly to write a decoder.
     * Use it only when you must use it at your own risk.
     */
    protected ChannelBuffer internalBuffer() {
        ChannelBuffer buf = this.cumulation;
        if (buf == null) {
            return ChannelBuffers.EMPTY_BUFFER;
        }
        return buf;
    }
View Full Code Here

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

        ChannelBuffer input = (ChannelBuffer) m;
        if (!input.readable()) {
            return;
        }

        ChannelBuffer cumulation = cumulation(ctx);
        needsCleanup = true;
        cumulation.discardReadBytes();
        cumulation.writeBytes(input);
        callDecode(ctx, e.getChannel(), cumulation, e.getRemoteAddress());
    }
View Full Code Here

                return;
            } else {
                needsCleanup = false;
            }

            ChannelBuffer cumulation = this.cumulation;
            this.cumulation = null;
            replayable.terminate();

            if (cumulation != null && cumulation.readable()) {
                // Make sure all data was read before notifying a closed channel.
                callDecode(ctx, e.getChannel(), cumulation, null);
            }

            // Call decodeLast() finally.  Please note that decodeLast() is
View Full Code Here

            ctx.sendUpstream(e);
        }
    }

    private ChannelBuffer cumulation(ChannelHandlerContext ctx) {
        ChannelBuffer buf = this.cumulation;
        if (buf == null) {
           
            if (cumulation == null) {
                ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
                buf = new UnsafeDynamicChannelBuffer(factory);
View Full Code Here

        ObjectOutputStream oout = new CompactObjectOutputStream(bout);
        oout.writeObject(msg);
        oout.flush();
        oout.close();

        ChannelBuffer encoded = bout.buffer();
        encoded.setInt(0, encoded.writerIndex() - 4);
        return encoded;
    }
View Full Code Here

   
    @Override
    protected Object decode(
            ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {

        ChannelBuffer frame = (ChannelBuffer) super.decode(ctx, channel, buffer);
        if (frame == null) {
            return null;
        }

        return new CompactObjectInputStream(
View Full Code Here

    @Override
    public ChannelGroupFuture write(Object message) {
        Map<Integer, ChannelFuture> futures =
            new LinkedHashMap<Integer, ChannelFuture>(size());
        if (message instanceof ChannelBuffer) {
            ChannelBuffer buf = (ChannelBuffer) message;
            for (Channel c: nonServerChannels.values()) {
                futures.put(c.getId(), c.write(buf.duplicate()));
            }
        } else {
            for (Channel c: nonServerChannels.values()) {
                futures.put(c.getId(), c.write(message));
            }
View Full Code Here

    @Override
    public ChannelGroupFuture write(Object message, SocketAddress remoteAddress) {
        Map<Integer, ChannelFuture> futures =
            new LinkedHashMap<Integer, ChannelFuture>(size());
        if (message instanceof ChannelBuffer) {
            ChannelBuffer buf = (ChannelBuffer) message;
            for (Channel c: nonServerChannels.values()) {
                futures.put(c.getId(), c.write(buf.duplicate(), remoteAddress));
            }
        } else {
            for (Channel c: nonServerChannels.values()) {
                futures.put(c.getId(), c.write(message, remoteAddress));
            }
View Full Code Here

TOP

Related Classes of io.netty.buffer.ChannelBuffer

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.