Package io.netty.buffer

Examples of io.netty.buffer.ChannelBuffer


        // Send the demo page and favicon.ico
        if (req.getUri().equals("/")) {
            HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);

            ChannelBuffer content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));

            res.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8");
            setContentLength(res, content.readableBytes());

            res.setContent(content);
            sendHttpResponse(ctx, req, res);
            return;
        } else if (req.getUri().equals("/favicon.ico")) {
View Full Code Here


        // Convert the number into a byte array.
        byte[] data = v.toByteArray();
        int dataLength = data.length;

        // Construct a message.
        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
        buf.writeByte((byte) 'F'); // magic number
        buf.writeInt(dataLength)// data length
        buf.writeBytes(data);      // data

        // Return the constructed message.
        return buf;
    }
View Full Code Here

    }

    @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

        }

        @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

        // A channel becomes unwritable when its internal buffer is full.
        // If you keep writing messages ignoring this property,
        // you will end up with an OutOfMemoryError.
        Channel channel = e.getChannel();
        while (channel.isWritable()) {
            ChannelBuffer m = nextMessage();
            if (m == null) {
                break;
            }
            channel.write(m);
        }
View Full Code Here

  protected Object encode(ChannelHandlerContext ctx, Channel channel,
      Object msg) throws Exception {
    if (!(msg instanceof PeerWireMessage))
      return msg;
    final PeerWireMessage message = (PeerWireMessage) msg;
    final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();

    if (handshaked && !(message instanceof KeepAliveMessage))
      buffer.writeInt(0x00);
    message.write(buffer);

    return buffer;
  }
View Full Code Here

  @Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel,
      Object msg) throws Exception {
    if (!(msg instanceof ChannelBuffer) || !handshaked)
      return msg;
    final ChannelBuffer buffer = (ChannelBuffer) msg;

    buffer.readerIndex(0);
    if (handshaked) {
      final int len = buffer.readableBytes() - 4;
      buffer.setInt(0, len);
    }

    return buffer;
  }
View Full Code Here

  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel,
      Object msg) throws Exception {
    if (!(msg instanceof ChannelBuffer))
      return msg;
    final ChannelBuffer buffer = (ChannelBuffer) msg;

    if (!handshaked) {
      final HandshakeMessage message = new HandshakeMessage();
      message.read(buffer);

      return message;
    } else {
      if(buffer.readableBytes() == 0)
        return new KeepAliveMessage();
     
      final byte opcode = buffer.readByte();
      final PeerWireMessage message;
      switch (opcode) {
      case CancelMessage.MESSAGE_ID:
        message = new CancelMessage();
        break;
View Full Code Here

            final boolean complete = sctpFrame.getMessageInfo().isComplete();
            if (complete) {
                if (cumulation == null) {
                    return sctpFrame.getPayloadBuffer();
                } else {
                    final ChannelBuffer extractedFrame = ChannelBuffers.wrappedBuffer(cumulation, sctpFrame.getPayloadBuffer());
                    cumulation = null;
                    return extractedFrame;
                }
            } else {
                if (cumulation == null) {
View Full Code Here

            bb.flip();

            final ChannelBufferFactory bufferFactory =
                    channel.getConfig().getBufferFactory();
            final int receivedBytes = bb.remaining();
            final ChannelBuffer buffer = bufferFactory.getBuffer(receivedBytes);
            buffer.setBytes(0, bb);
            buffer.writerIndex(receivedBytes);

            recvBufferPool.release(bb);

            // Update the predictor.
            predictor.previousReceiveBufferSize(receivedBytes);
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.