Examples of ChannelBuffer


Examples of com.alibaba.dubbo.remoting.buffer.ChannelBuffer

    @Override
    public NextAction handleWrite(FilterChainContext context) throws IOException {
        Connection<?> connection = context.getConnection();
        GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
        try {
            ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // 不需要关闭
           
            Object msg = context.getMessage();
            codec.encode(channel, channelBuffer, msg);
           
            GrizzlyChannel.removeChannelIfDisconnectd(connection);
            Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
            buffer.put(channelBuffer.toByteBuffer());
            buffer.flip();
            buffer.allowBufferDispose(true);
            context.setMessage(buffer);
        } finally {
            GrizzlyChannel.removeChannelIfDisconnectd(connection);
View Full Code Here

Examples of com.facebook.presto.jdbc.internal.netty.buffer.ChannelBuffer

    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
        if (!(msg instanceof ChannelBuffer) || finished.get()) {
            return msg;
        }

        ChannelBuffer result;
        synchronized (z) {
            try {
                // Configure input.
                ChannelBuffer uncompressed = (ChannelBuffer) msg;
                byte[] in = new byte[uncompressed.readableBytes()];
                uncompressed.readBytes(in);
                z.next_in = in;
                z.next_in_index = 0;
                z.avail_in = in.length;

                // Configure output.
                byte[] out = new byte[(int) Math.ceil(in.length * 1.001) + 12];
                z.next_out = out;
                z.next_out_index = 0;
                z.avail_out = out.length;

                // Note that Z_PARTIAL_FLUSH has been deprecated.
                int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
                if (resultCode != JZlib.Z_OK) {
                    ZlibUtil.fail(z, "compression failure", resultCode);
                }

                if (z.next_out_index != 0) {
                    result = ctx.getChannel().getConfig().getBufferFactory().getBuffer(
                            uncompressed.order(), out, 0, z.next_out_index);
                } else {
                    result = ChannelBuffers.EMPTY_BUFFER;
                }
            } finally {
                // Deference the external references explicitly to tell the VM that
View Full Code Here

Examples of io.netty.buffer.ChannelBuffer

        ChannelBuffer[] data = new ChannelBuffer[size];
        for (int i = 0; i < data.length; i ++) {
            data[i] = (ChannelBuffer) pendingWrites.get(i).getMessage();
        }

        ChannelBuffer composite = ChannelBuffers.wrappedBuffer(data);
        ChannelFuture future = Channels.future(ctx.getChannel());
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future)
                    throws Exception {
View Full Code Here

Examples of net.gleamynode.netty.buffer.ChannelBuffer

            context.sendDownstream(evt);
            return;
        }

        // Otherwise, all messages are encrypted.
        ChannelBuffer msg = (ChannelBuffer) e.getMessage();
        PendingWrite pendingWrite =
            new PendingWrite(evt.getFuture(), msg.toByteBuffer(msg.readerIndex(), msg.readableBytes()));
        synchronized (pendingUnencryptedWrites) {
            pendingUnencryptedWrites.offer(pendingWrite);
        }

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

Examples of org.elasticsearch.common.netty.buffer.ChannelBuffer

    public static void main(String[] args) {
        final int payloadSize = 100;
        int CYCLE_SIZE = 50000;
        final long NUMBER_OF_ITERATIONS = 500000;

        ChannelBuffer message = ChannelBuffers.buffer(100);
        for (int i = 0; i < message.capacity(); i++) {
            message.writeByte((byte) i);
        }

        // Configure the server.
        ServerBootstrap serverBootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        oout.writeObject(e.getMessage());
        ExternalizeUtil.writeCollection(oout, oout.getReferences());
        oout.flush();
        oout.close();

        ChannelBuffer encoded = bout.buffer();
        encoded.setInt(0, encoded.writerIndex() - 4);
        write(ctx, e.getFuture(), encoded, e.getRemoteAddress());
    for (InputStream is : oout.getStreams()) {
      Channels.write(ctx.getChannel(), new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)));
    }
    }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

      super(in, CHUNK_SIZE);
    }
     
    @Override
    public Object nextChunk() throws Exception {
      ChannelBuffer cb = (ChannelBuffer)super.nextChunk();
      int length = cb.capacity();
      ChannelBuffer prefix = wrappedBuffer(new byte[2]);
      prefix.setShort(0, (short)length);
      if (!hasNextChunk()) {
        //append a 0 short
        return wrappedBuffer(prefix, cb, wrappedBuffer(new byte[2]));
      }
     
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    sb.append('"');
 
 
  @Override
  public void sslDenied() {
    ChannelBuffer buffer = ChannelBuffers.directBuffer(1);
    buffer.writeByte('N');
    Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());   
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    int len = buff.length;
    this.outBuffer = null;
    this.dataOut = null;
   
    // now build the wire contents.
    ChannelBuffer buffer = ChannelBuffers.directBuffer(len+5);
    buffer.writeByte((byte)this.messageType);
    buffer.writeInt(len+4);
    buffer.writeBytes(buff);
    Channels.write(this.ctx, this.message.getFuture(), buffer, this.message.getRemoteAddress());
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        String key1 = req.getHeader(SEC_WEBSOCKET_KEY1);
        String key2 = req.getHeader(SEC_WEBSOCKET_KEY2);
        int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
        int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
        long c = req.getContent().readLong();
        ChannelBuffer input = ChannelBuffers.buffer(16);
        input.writeInt(a);
        input.writeInt(b);
        input.writeLong(c);
        try {
            ChannelBuffer output = ChannelBuffers.wrappedBuffer(
                    MessageDigest.getInstance("MD5").digest(input.array()));
            res.setContent(output);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(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.