Package io.netty.buffer

Examples of io.netty.buffer.ByteBufOutputStream


    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        final int length = in.readableBytes();
        final InputStream bbIn = new ByteBufInputStream(in);

        final ByteBufOutputStream bbOut = new ByteBufOutputStream(out);
        bbOut.writeByte(properties);
        bbOut.writeInt(littleEndianDictionarySize);
        bbOut.writeLong(Long.reverseBytes(length));
        encoder.code(bbIn, bbOut, -1, -1, null);

        bbIn.close();
        bbOut.close();
    }
View Full Code Here


                buf.writeBytes(packet.getData().toString().getBytes(CharsetUtil.UTF_8));
                break;
            }

            case OPEN: {
                ByteBufOutputStream out = new ByteBufOutputStream(buf);
                if (jsonp) {
                    jsonSupport.writeJsonpValue(out, packet.getData());
                } else {
                    jsonSupport.writeValue(out, packet.getData());
                }
                break;
            }

            case MESSAGE: {
                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[] {','});
                    }
                }

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

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

                if (packet.getSubType() == PacketType.EVENT
                        || packet.getSubType() == PacketType.ERROR) {
                    values.add(packet.getName());
                }

                if (packet.getSubType() == PacketType.EVENT
                        || packet.getSubType() == PacketType.ACK
                            || packet.getSubType() == PacketType.ERROR) {
                    List<Object> args = packet.getData();
                    values.addAll(args);
                    ByteBufOutputStream out = new ByteBufOutputStream(buf);
                    if (jsonp) {
                        jsonSupport.writeJsonpValue(out, values);
                    } else {
                        if (binary) {
                            // handling websocket encoding bug
                            ByteBuf b = allocateBuffer(allocator);
                            try {
                                ByteBufOutputStream os = new ByteBufOutputStream(b);
                                jsonSupport.writeValue(os, values);

                                CharsetEncoder enc = CharsetUtil.ISO_8859_1.newEncoder();
                                String str = b.toString(CharsetUtil.ISO_8859_1);
                                if (enc.canEncode(str)) {
View Full Code Here

                    ObjectOutputStream objectOutstream = null;
                    try {
                        // Write the test result
                        out.discardReadBytes();
                        objectOutstream = new ObjectOutputStream(new ByteBufOutputStream(out));
                        objectOutstream.writeObject(testResult);
                        objectOutstream.flush();
                        ctx.flush();
                        return;
View Full Code Here

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        final int length = in.readableBytes();
        final InputStream bbIn = new ByteBufInputStream(in);

        final ByteBufOutputStream bbOut = new ByteBufOutputStream(out);
        bbOut.writeByte(properties);
        bbOut.writeInt(littleEndianDictionarySize);
        bbOut.writeLong(Long.reverseBytes(length));
        encoder.code(bbIn, bbOut, -1, -1, null);

        bbIn.close();
        bbOut.close();
    }
View Full Code Here

        private final ByteBuf outputBuffer;

        StreamOut(final MuxStream meta) {
            this.meta = meta;
            this.outputBuffer = PooledByteBufAllocator.DEFAULT.ioBuffer(0);
            this.output = new ByteBufOutputStream(outputBuffer);
        }
View Full Code Here

    private ByteBufOutputStream out;

    private boolean flushed;

    public NettyServletOutputStream(HttpContent httpContent) {
        this.out = new ByteBufOutputStream(httpContent.content());
    }
View Full Code Here

            super(message, possibleRetransmit, isChunking, chunkThreshold, conduitName, url);
            csPolicy = getClient(message);
            entity  = message.get(NettyHttpClientRequest.class);
            int bufSize = csPolicy.getChunkLength() > 0 ? csPolicy.getChunkLength() : 16320;
            outBuffer = Unpooled.buffer(bufSize);
            outputStream = new ByteBufOutputStream(outBuffer);
        }
View Full Code Here

                this.url = new URI(newURL);
                setupConnection(outMessage, this.url, csPolicy);
                entity = outMessage.get(NettyHttpClientRequest.class);
                //reset the buffers
                outBuffer.clear();
                outputStream = new ByteBufOutputStream(outBuffer);

            } catch (URISyntaxException e) {
                throw new IOException(e);
            }
        }
View Full Code Here

      if(rawBodyLength > 0){
        fullLength += (RAW_BODY_TAG_LENGTH + getRawVarintSize(rawBodyLength) + rawBodyLength);
      }

      ByteBuf buf = ctx.alloc().buffer();
      OutputStream os = new ByteBufOutputStream(buf);
      CodedOutputStream cos = CodedOutputStream.newInstance(os);

      // write full length first (this is length delimited stream).
      cos.writeRawVarint32(fullLength);
     
View Full Code Here

    protected void encode(ChannelHandlerContext chc, Message message, ByteBuf bb) throws Exception {
        try {
            if (Server.DEBUG_SEND) {
                Server.logger.log(Level.FINER, "encoding "+System.identityHashCode(message)+" "+message);
            }
            server.encode(new ByteBufOutputStream(bb),message);
        }
        catch(Exception ex) {
            // TODO if i do not log this here, it does not seem to be logged
            // fields that are LAZY but we have no transaction create a error here
            LobbyServer.logger.log(Level.WARNING, "error in encode", ex);
View Full Code Here

TOP

Related Classes of io.netty.buffer.ByteBufOutputStream

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.