Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.writeBytes()


            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
                        ByteBuf buf = ctx.alloc().buffer(data.length);
                        buf.writeBytes(data);
                        ctx.writeAndFlush(buf);
                    }

                    @Override
                    public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
View Full Code Here


      for (int i = 0; i < trafficThreads.length; i++) {
        Thread t = new Thread() {
          @Override
          public void run() {
            ByteBuf m = ByteBufAllocator.DEFAULT.buffer(messageBytes.length);
            m.writeBytes(messageBytes);
            while (!isShutdown.get()) {
              for (int i = 0; i < numPartitions; i++) {
                HelixMessageScope scope =
                    new HelixMessageScope.Builder().cluster("CLUSTER").resource("RESOURCE")
                        .partition("PARTITION_" + i).sourceInstance(localhost + "_" + port).build();
View Full Code Here

        buf.writeByte(type);

        switch (packet.getType()) {

            case PONG: {
                buf.writeBytes(packet.getData().toString().getBytes(CharsetUtil.UTF_8));
                break;
            }

            case OPEN: {
                ByteBufOutputStream out = new ByteBufOutputStream(buf);
View Full Code Here

                byte subType = toChar(packet.getSubType().getValue());
                buf.writeByte(subType);

                if (packet.getSubType() == PacketType.CONNECT) {
                    if (!packet.getNsp().isEmpty()) {
                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                    }
                } else {
                    if (!packet.getNsp().isEmpty()) {
                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                        buf.writeBytes(new byte[] {','});
View Full Code Here

                    if (!packet.getNsp().isEmpty()) {
                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                    }
                } else {
                    if (!packet.getNsp().isEmpty()) {
                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                        buf.writeBytes(new byte[] {','});
                    }
                }

                if (packet.getAckId() != null) {
View Full Code Here

                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                    }
                } else {
                    if (!packet.getNsp().isEmpty()) {
                        buf.writeBytes(packet.getNsp().getBytes(CharsetUtil.UTF_8));
                        buf.writeBytes(new byte[] {','});
                    }
                }

                if (packet.getAckId() != null) {
                    byte[] ackId = toChars(packet.getAckId());
View Full Code Here

                    }
                }

                if (packet.getAckId() != null) {
                    byte[] ackId = toChars(packet.getAckId());
                    buf.writeBytes(ackId);
                }

                List<Object> values = new ArrayList<Object>();

                if (packet.getSubType() == PacketType.EVENT
View Full Code Here

    private static void addAuth(final ChannelHandlerContext ctx, final HttpRequest request, final String user,
        final String password) {
        final String pw = password == null ? "" : password;

        ByteBuf raw = ctx.alloc().buffer(user.length() + pw.length() + 1);
        raw.writeBytes((user + ":" + pw).getBytes(CHARSET));
        ByteBuf encoded = Base64.encode(raw);
        request.headers().add(HttpHeaders.Names.AUTHORIZATION, "Basic " + encoded.toString(CHARSET));
        encoded.release();
        raw.release();
    }
View Full Code Here

    private static BinaryMemcacheRequest handleObserveRequest(final ChannelHandlerContext ctx, final ObserveRequest msg) {
        String key = msg.key();
        ByteBuf content = ctx.alloc().buffer();
        content.writeShort(msg.partition());
        content.writeShort(key.length());
        content.writeBytes(key.getBytes(CHARSET));

        BinaryMemcacheRequest request = new DefaultFullBinaryMemcacheRequest("", Unpooled.EMPTY_BUFFER, content);
        request.setOpcode(OP_OBSERVE);
        request.setTotalBodyLength(content.readableBytes());
        return request;
View Full Code Here

        if (request instanceof GetRequest || request instanceof ReplicaGetRequest) {
            int flags = 0;
            if (msg.getExtrasLength() > 0) {
                final ByteBuf extrasReleased = msg.getExtras();
                final ByteBuf extras = ctx.alloc().buffer(msg.getExtrasLength());
                extras.writeBytes(extrasReleased, extrasReleased.readerIndex(), extrasReleased.readableBytes());
                flags = extras.getInt(0);
                extras.release();
            }
            response = new GetResponse(status, cas, flags, bucket, content, request);
        } else if (request instanceof GetBucketConfigRequest) {
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.