Examples of ChannelBuffer


Examples of org.jboss.netty.buffer.ChannelBuffer

            case MASKING_KEY:
                maskingKey = buffer.readBytes(4);
                checkpoint(State.PAYLOAD);
            case PAYLOAD:
                checkpoint(State.FRAME_START);
                ChannelBuffer frame = buffer.readBytes(currentFrameLength);
                unmask(frame);

                if (this.opcode == OPCODE_CONT) {
                    this.opcode = fragmentOpcode;
                    frames.add(frame);

                    frame = channel.getConfig().getBufferFactory().getBuffer(0);
                    for (ChannelBuffer channelBuffer : frames) {
                        frame.ensureWritableBytes(channelBuffer.readableBytes());
                        frame.writeBytes(channelBuffer);
                    }

                    this.fragmentOpcode = null;
                    frames.clear();
                }

                if (this.opcode == OPCODE_TEXT) {
                    if (frame.readableBytes() > MAX_LENGTH) {
                        throw new TooLongFrameException();
                    }
                    return new DefaultWebSocketFrame(0x00, frame);
                } else if (this.opcode == OPCODE_BINARY) {
                    return new DefaultWebSocketFrame(0xFF, frame);
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    @Override
    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
        if (msg instanceof WebSocketFrame) {
            WebSocketFrame frame = (WebSocketFrame) msg;
            ChannelBuffer data = frame.getBinaryData();
            ChannelBuffer encoded =
                    channel.getConfig().getBufferFactory().getBuffer(
                            data.order(), data.readableBytes() + 6);

            byte opcode;
            if(frame instanceof Ping) {
                opcode = OPCODE_PING;
            } else if(frame instanceof Pong) {
                opcode = OPCODE_PONG;
            } else {
                opcode = frame.isText() ? OPCODE_TEXT : OPCODE_BINARY;
            }
            encoded.writeByte(0x80 | opcode);

            int length = data.readableBytes();
            if (length < 126) {
                encoded.writeByte(length);
            } else if (length < 65535) {
                encoded.writeByte(126);
                encoded.writeShort(length);
            } else {
                encoded.writeByte(127);
                encoded.writeInt(length);
            }

            encoded.writeBytes(data, data.readerIndex(), data.readableBytes());
            encoded = encoded.slice(0, encoded.writerIndex());
            return encoded;
        }
        return msg;
    }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    @Override
    public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        Command cmd = (Command) e.getMessage();
        Channel channel = ctx.getChannel();
        ChannelBuffer buf = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());
        cmd.encode(buf);
        Channels.write(ctx, e.getFuture(), buf);
    }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        Channels.write(ctx, e.getFuture(), buf);
    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        ChannelBuffer input = (ChannelBuffer) e.getMessage();
        if (!input.readable()) return;

        buffer.discardReadBytes();
        buffer.writeBytes(input);

        decode(ctx, buffer);
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

            }

            if (request.isChunked()) {
                readingChunks = true;
            } else {
                ChannelBuffer content = request.getContent();
                if (content.readable()) {
                    buf.append("CONTENT: " + content.toString(CharsetUtil.UTF_8) + "\r\n");
                }
                writeResponse(e);
            }
        } else {
            HttpChunk chunk = (HttpChunk) e.getMessage();
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

            if (response.getStatus().getCode() == 200 && response.isChunked()) {
                readingChunks = true;
                System.out.println("CHUNKED CONTENT {");
            } else {
                ChannelBuffer content = response.getContent();
                if (content.readable()) {
                    System.out.println("CONTENT {");
                    System.out.println(content.toString(CharsetUtil.UTF_8));
                    System.out.println("} END OF CONTENT");
                }
            }
        } else {
            HttpChunk chunk = (HttpChunk) e.getMessage();
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        }

        @Override
        public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e)
                throws Exception {
            ChannelBuffer msg = (ChannelBuffer) e.getMessage();
            //System.out.println("<<< " + ChannelBuffers.hexDump(msg));
            synchronized (trafficLock) {
                inboundChannel.write(msg);
                // If inboundChannel is saturated, do not read until notified in
                // HexDumpProxyInboundHandler.channelInterestChanged().
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e)
            throws Exception {
        ChannelBuffer msg = (ChannelBuffer) e.getMessage();
        //System.out.println(">>> " + ChannelBuffers.hexDump(msg));
        synchronized (trafficLock) {
            outboundChannel.write(msg);
            // If outboundChannel is saturated, do not read until notified in
            // OutboundHandler.channelInterestChanged().
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

  @Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel, Object message) throws Exception
  {
    Message m = (Message) message;
    ChannelBuffer buffer = buffer(m.getMessage().length() + 2);
    buffer.writeByte(m.getCode());
    buffer.writeBytes(encoder.encode(CharBuffer.wrap(m.getMessage())));
    buffer.writeByte((byte) 0);
    // System.out.println("encode " + buffer.toString("UTF-8"));
    return buffer;
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

public class MessageDecoder extends OneToOneDecoder
{
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, Object message) throws Exception
  {
    ChannelBuffer b = (ChannelBuffer) message;

    byte code = b.readByte();
    // TODO remove the nul
    b.writerIndex(b.writerIndex());
    String msg = b.toString(Charset.defaultCharset().displayName());
    Message result = new Message(code, msg);
    return result;
  }
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.