Package org.jboss.netty.buffer

Examples of org.jboss.netty.buffer.ChannelBufferOutputStream


        if (e.getMessage() instanceof ChunkedInput) {
            ctx.sendDownstream(evt);
            return;
        }
       
        ChannelBufferOutputStream bout =
            new ChannelBufferOutputStream(dynamicBuffer(
                    estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
        bout.write(LENGTH_PLACEHOLDER);
        final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout);
        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


    /**
     * create a buffer containing the encoding of this batch
     */
    ChannelBuffer buffer() throws Exception {
        ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));
       
        for (TaskMessage msg : msgs)
            writeTaskMessage(bout, msg);

        //add a END_OF_BATCH indicator
        ControlMessage.EOB_MESSAGE.write(bout);

        bout.close();

        return bout.buffer();
    }
View Full Code Here

    private void writeResponse(MessageEvent e) {
      HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
      response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");

      ChannelBuffer content = ChannelBuffers.dynamicBuffer();
      Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
      reportAdapter.toJson(report.get(), writer);
      try {
        writer.close();
      } catch (IOException e1) {
        LOG.error("error writing resource report", e1);
View Full Code Here

        this.estimatedLength = estimatedLength;
    }

    @Override
    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
        ChannelBufferOutputStream bout =
            new ChannelBufferOutputStream(dynamicBuffer(
                    estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
        bout.write(LENGTH_PLACEHOLDER);
        ObjectOutputStream oout = new CompactObjectOutputStream(bout);
        oout.writeObject(msg);
        oout.flush();
        oout.close();

        ChannelBuffer encoded = bout.buffer();
        encoded.setInt(0, encoded.writerIndex() - 4);
        return encoded;
    }
View Full Code Here

public class DataUtil {
   
    public static ChannelBuffer compress(ChannelBuffer in) throws IOException {
        ChannelBufferInputStream channelBufferInputStream = new ChannelBufferInputStream(in);
        ChannelBuffer out = ChannelBuffers.dynamicBuffer(in.readableBytes());
        ChannelBufferOutputStream channelBufferOutputStream = new ChannelBufferOutputStream(out);

        compress(ByteStreams.toByteArray(channelBufferInputStream), channelBufferOutputStream);
        return out;
    }
View Full Code Here

            ctx.getChannel().write(httpResponse).addListener(ChannelFutureListener.CLOSE);
        } catch (Exception e) {
            HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
            if (logger.isDebugEnabled()) {
                ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer();
                PrintWriter printWriter = new PrintWriter(new ChannelBufferOutputStream(channelBuffer));
                e.printStackTrace(printWriter);
                printWriter.close();
                httpResponse.setContent(channelBuffer);
            }
            logger.error("web server error: ", e);
View Full Code Here

        HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
        httpResponse.setHeader("id", errorid);
        if (logger.isDebugEnabled()) {
            ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer();
            PrintWriter printWriter = new PrintWriter(new ChannelBufferOutputStream(channelBuffer));
            e.getCause().printStackTrace(printWriter);
            printWriter.close();
            httpResponse.setContent(channelBuffer);
        }
        ctx.getChannel().write(httpResponse).addListener(ChannelFutureListener.CLOSE);
View Full Code Here

        }
    }

    public void writeJSON(Object object) throws IOException {
        ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer();
        ChannelBufferOutputStream outputStream = new ChannelBufferOutputStream(channelBuffer);
        mapper.writeValue(outputStream, object);
        outputStream.close();
        write(channelBuffer);
    }
View Full Code Here

        write(channelBuffer);
    }

    public void writeXML(Object object) {
        ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer();
        ChannelBufferOutputStream outputStream = new ChannelBufferOutputStream(channelBuffer);
        xstreamXML.toXML(object, outputStream);
        write(channelBuffer);
    }
View Full Code Here

                                                    int maxSize,
                                                    DbusEventsStatisticsCollector stats)
      throws ScnNotFoundException, OffsetNotFoundException, IOException
  {
    ChannelBuffer tmpBuf = ChannelBuffers.buffer(new DbusEventV1Factory().getByteOrder(), maxSize);
    OutputStream tmpOS = new ChannelBufferOutputStream(tmpBuf);
    WritableByteChannel tmpChannel = java.nio.channels.Channels.newChannel(tmpOS);

    StreamEventsArgs args = new StreamEventsArgs(maxSize).setStatsCollector(stats);

    buf.streamEvents(cp, tmpChannel, args);
View Full Code Here

TOP

Related Classes of org.jboss.netty.buffer.ChannelBufferOutputStream

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.