Package io.netty.buffer

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


        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = Hex.decode(str);
        b.writerIndex( offset );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }

    public static String hexSlice(JSObject object, int start, int end) {
View Full Code Here


        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = Base64.decode(str);
        b.writerIndex( offset );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes(bytes, 0, len);
        b.writerIndex(Math.max(b.writerIndex(), origWriter));
        return len;
    }

    public static String base64Slice(JSObject object, int start, int end) {
View Full Code Here

    public static long binaryWrite(JSObject object, String str, int offset, int len) {
        ByteBuf b = extract( object );
        int origWriter = b.writerIndex();
        byte[] bytes = str.getBytes( BINARY );
        len = Math.min( bytes.length, Math.min( len, b.writableBytes() ) );
        b.writeBytes( bytes, 0, len );
        b.writerIndex( Math.max( b.writerIndex(), origWriter ) );
        return len;
    }

    public static String binarySlice(JSObject object, int start, int end) {
View Full Code Here

    public static ByteBuf toBuf(BigInteger i) {
        byte[] array = i.toByteArray();
        int byteLen = (int) Math.ceil( i.bitLength() / 8.0  );
        ByteBuf buf = Unpooled.buffer( byteLen );
        buf.writeBytes( array, array.length - byteLen, byteLen );
        return buf;
    }

    public static BigInteger fromBuf(ByteBuf buf) {
        byte[] array = new byte[ buf.readableBytes() + 1 ];
View Full Code Here

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));

                encodedMessage = allocator.buffer((int) output.total());
                encodedMessage.writeBytes(output.toBytes());
            }

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));

                encodedMessage = allocator.buffer((int) size);
                encodedMessage.writeBytes(output.toBytes());
            }

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

            message.put(SerTokens.TOKEN_RESULT, result);
            message.put(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId() : null);

            final byte[] payload = obtainMapper().writeValueAsBytes(message);
            encodedMessage = allocator.buffer(payload.length);
            encodedMessage.writeBytes(payload);

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

        try {
            final byte[] header = obtainHeader();
            final byte[] payload = obtainMapper().writeValueAsBytes(requestMessage);

            encodedMessage = allocator.buffer(header.length + payload.length);
            encodedMessage.writeBytes(header);
            encodedMessage.writeBytes(payload);

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

            final byte[] header = obtainHeader();
            final byte[] payload = obtainMapper().writeValueAsBytes(requestMessage);

            encodedMessage = allocator.buffer(header.length + payload.length);
            encodedMessage.writeBytes(header);
            encodedMessage.writeBytes(payload);

            return encodedMessage;
        } catch (Exception ex) {
            if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
View Full Code Here

            @Override
            protected void initChannel(DatagramChannel ch) throws Exception {
                ch.pipeline().addLast(new SimpleChannelInboundHandler<DatagramPacket>() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data, InetSocketAddress address) {
                        ByteBuf buf = ctx.alloc().buffer(data.length);
                        buf.writeBytes(data);
                        ctx.writeAndFlush(new DatagramPacket(buf, address));
                    }
                 
                    @Override
                    public void channelActive(ChannelHandlerContext ctx) throws Exception {
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.