Package org.jboss.netty.buffer

Examples of org.jboss.netty.buffer.ChannelBuffer.array()


       * pipeline); it fits single ddf message only w/o delimiters;
       */
      final ChannelBuffer frameBuffer = (ChannelBuffer) messageRAW;

      /* underlying frame array */
      byte[] array = frameBuffer.array();

      /*
       * silent ignore of invalid chunks sometimes sent by JERQ; DDF must
       * have at least 1 command char and 1 terminator
       */
 
View Full Code Here


       
            ChannelBuffer buf = (ChannelBuffer) e.getMessage();     
            byte[] line;
           
            if (buf.hasArray()) {
                line = buf.array();
            } else {
                // copy the ChannelBuffer to a byte array to process the LineHandler
                line = new byte[buf.capacity()];
                buf.getBytes(0, line);
            }
View Full Code Here

        ChannelBuffer buf = (ChannelBuffer) e.getMessage();     
        byte[] line;
        if (buf.hasArray()) {
            if (buf.arrayOffset() == 0 && buf.readableBytes() == buf.capacity()) {
                // we have no offset and the length is the same as the capacity. Its safe to reuse the array without copy it first
                line = buf.array();
            } else {
                // copy the ChannelBuffer to a byte array to process the LineHandler
                line = new byte[buf.readableBytes()];
                buf.getBytes(0, line);
            }
View Full Code Here

                return msg;
            } else {
                // it may be empty, then return null
                ChannelBuffer cb = (ChannelBuffer) msg;
                if (cb.hasArray() && cb.readable()) {
                    return cb.array();
                } else {
                    return null;
                }
            }
        }
View Full Code Here

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
      // Get handle from create response
      ChannelBuffer buf = (ChannelBuffer) e.getMessage();
      XDR rsp = new XDR(buf.array());
      if (rsp.getBytes().length == 0) {
        LOG.info("rsp length is zero, why?");
        return;
      }
      LOG.info("rsp length=" + rsp.getBytes().length);
View Full Code Here

        byte[] bytes = data.getBytes();
        ch.write(new PongWebSocketFrame(ChannelBuffers.copiedBuffer(bytes)));
        WebSocketFrame frame = queue.poll(5, TimeUnit.SECONDS);
        if (frame instanceof PingWebSocketFrame) {
            ChannelBuffer d = frame.getBinaryData();
            return new String(d.array(), 0, d.readableBytes());
        } else {
            throw new Exception("pong frame expected, instead of " + frame);
        }
    }
View Full Code Here

        byte[] bytes = data.getBytes();
        ch.write(new PingWebSocketFrame(ChannelBuffers.copiedBuffer(bytes)));
        WebSocketFrame frame = queue.poll(5, TimeUnit.SECONDS);
        if (frame instanceof PongWebSocketFrame) {
            ChannelBuffer d = frame.getBinaryData();
            return new String(d.array(), 0, d.readableBytes());
        } else {
            throw new Exception("pong frame expected, instead of " + frame);
        }
    }
View Full Code Here

      return null;
    }
    ChannelBuffer channelBuffer = buffer.readBytes(scmpFrameSize);
    // reset the frame size
    this.scmpFrameSize = 0;
    return channelBuffer.array();
  }
}
View Full Code Here

            // Validate stored data.
            ChannelBuffer buffer = data.getChannelBuffer();

            assertEquals(0, buffer.readerIndex());
            assertEquals(bytes.length, buffer.writerIndex());
            assertArrayEquals(bytes, Arrays.copyOf(buffer.array(), bytes.length));
        }
    }

    /** Memory-based HTTP data implementation for test purposes. */
    private static final class TestHttpData extends AbstractMemoryHttpData {
View Full Code Here

        // The first int is the size of the message, excluding the 4 bytes
        // needed for the size itself, hence the `-4'.
        payload.setInt(offset, payload.readableBytes() - 4); // 4 bytes
        try {
          final CodedOutputStream output =
            CodedOutputStream.newInstance(payload.array(), 4 + offset,
                                          1 + pblen);
          output.writeRawByte(pblen)// varint but always on 1 byte here.
          header.writeTo(output);
          output.checkNoSpaceLeft();
        } catch (IOException e) {
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.