Example usage for io.netty.buffer ByteBufOutputStream ByteBufOutputStream

List of usage examples for io.netty.buffer ByteBufOutputStream ByteBufOutputStream

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufOutputStream ByteBufOutputStream.

Prototype

public ByteBufOutputStream(ByteBuf buffer) 

Source Link

Document

Creates a new stream which writes data to the specified buffer .

Usage

From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImpl.java

License:Apache License

/**
 * Write the odata content to netty response content
 * @param odataResponse/*  w w w. j av  a2s.  c o m*/
 * @param response
 */
static void writeContent(final ODataResponse odataResponse, final HttpResponse response) {
    ODataContent res = odataResponse.getODataContent();
    res.write(Channels.newChannel(new ByteBufOutputStream(((HttpContent) response).content())));
}

From source file:org.apache.olingo.netty.server.core.ODataNettyHandlerImpl.java

License:Apache License

/** 
 * Copy OData content to netty content//w  w w  .java  2s  .c  o  m
 * @param input
 * @param response
 */
static void copyContent(final ReadableByteChannel input, final HttpResponse response) {
    WritableByteChannel output = null;
    try {
        ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
        output = Channels.newChannel(new ByteBufOutputStream(((HttpContent) response).content()));
        while (input.read(inBuffer) > 0) {
            inBuffer.flip();
            output.write(inBuffer);
            inBuffer.clear();
        }
    } catch (IOException e) {
        throw new ODataRuntimeException("Error on reading request content", e);
    } finally {
        closeStream(input);
        closeStream(output);
    }
}

From source file:org.apache.qpid.jms.message.facade.test.JmsTestBytesMessageFacade.java

License:Apache License

@Override
public OutputStream getOutputStream() throws JMSException {
    if (bytesIn != null) {
        throw new IllegalStateException("Body is being read from, cannot perform a write.");
    }/*  w  ww .j  a va 2  s  .  c  o  m*/

    if (bytesOut == null) {
        bytesOut = new ByteBufOutputStream(Unpooled.buffer());
        content = Unpooled.EMPTY_BUFFER;
    }

    return bytesOut;
}

From source file:org.apache.qpid.jms.provider.amqp.message.AmqpJmsBytesMessageFacade.java

License:Apache License

@Override
public OutputStream getOutputStream() throws JMSException {
    if (bytesIn != null) {
        throw new IllegalStateException("Body is being read from, cannot perform a write.");
    }//from  w  w  w  . j a  v a  2s.c  o m

    if (bytesOut == null) {
        bytesOut = new ByteBufOutputStream(Unpooled.buffer());
        setBody(EMPTY_BODY);
    }

    return bytesOut;
}

From source file:org.bridje.http.impl.HttpBridletResponseImpl.java

License:Apache License

public HttpBridletResponseImpl(ByteBuf buffer) {
    this.buffer = buffer;
    this.buffer.retain();
    out = new ByteBufOutputStream(buffer);
    this.headers = new LinkedHashMap<>();
}

From source file:org.curioswitch.curiostack.gcloud.storage.StorageClient.java

License:Open Source License

private static HttpData serializeRequest(Object request, ByteBufAllocator alloc) {
    ByteBuf buf = alloc.buffer();//from w  w w .j  a  va2 s .c o  m
    try (ByteBufOutputStream os = new ByteBufOutputStream(buf)) {
        OBJECT_MAPPER.writeValue((DataOutput) os, request);
    } catch (IOException e) {
        buf.release();
        throw new UncheckedIOException("Could not serialize resource JSON to buffer.", e);
    }

    return new ByteBufHttpData(buf, true);
}

From source file:org.curioswitch.gradle.plugins.gcloud.buildcache.CloudStorageBuildCacheService.java

License:Open Source License

@Override
public void store(BuildCacheKey buildCacheKey, BuildCacheEntryWriter buildCacheEntryWriter) {
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer((int) buildCacheEntryWriter.getSize());

    try {//from w w  w  .  j ava  2s .  co m
        try (ByteBufOutputStream os = new ByteBufOutputStream(buf)) {
            buildCacheEntryWriter.writeTo(os);
        } catch (IOException e) {
            logger.warn("Couldn't write cache entry to buffer.", e);
            return;
        }

        FileWriter writer = cloudStorage.createFile(buildCacheKey.getHashCode(), ImmutableMap.of()).join();
        while (buf.readableBytes() > 0) {
            ByteBuf chunk = buf.readRetainedSlice(Math.min(buf.readableBytes(), 10 * 4 * 256 * 1000));
            if (buf.readableBytes() > 0) {
                getUnchecked(writer.write(chunk));
            } else {
                writer.writeAndClose(chunk).join();
            }
        }
    } catch (Throwable t) {
        logger.warn("Exception writing to cloud storage, ignoring.", t);
    } finally {
        buf.release();
    }
}

From source file:org.deephacks.vertxrs.VertxHttpResponse.java

License:Apache License

public VertxHttpResponse(HttpServerRequest request, ResteasyProviderFactory providerFactory) {
    this.response = request.response();
    this.providerFactory = providerFactory;
    this.underlyingOutputStream = new ByteBufOutputStream(Unpooled.buffer());
    this.outputStream = underlyingOutputStream;
    this.buffer = new Buffer(underlyingOutputStream.buffer());
    this.request = request;
    this.outputHeaders = new MultivaluedMapImpl<>();
    this.keepAlive = isKeepAlive(request);
}

From source file:org.gameoss.gridcast.p2p.serialization.ProtostuffEncoder.java

License:Apache License

/**
 * Expose serializer for sharing serialization and unit testing.
 *
 * @param registry/*from w  ww.j  av a  2 s .c om*/
 * @param buf
 * @return
 * @throws IOException
 */
public static ByteBuf serializeToByteBuf(MessageRegistry registry, ByteBuf buf, Object msg) throws IOException {
    // write class id
    int classIdx = registry.getIdFromClass(msg.getClass());
    buf.writeInt(classIdx);

    // write serialized object
    Schema schema = RuntimeSchema.getSchema(msg.getClass());
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate(1024);
    ProtostuffIOUtil.writeTo(new ByteBufOutputStream(buf), msg, schema, linkedBuffer);

    return buf;
}

From source file:org.helios.octo.server.io.ChannelOutputStream.java

License:Open Source License

/**
 * Creates a new ChannelOutputStream/*from   w w  w  .  ja  va  2  s  .  c o  m*/
 * @param isStdOut true if this is std-out, false for std-err
 * @param channel The channel the output stream will write to
 */
private ChannelOutputStream(boolean isStdOut, Channel channel) {
    this.channel = channel;
    this.isStdOut = isStdOut;
    os.set(new ByteBufOutputStream(channel.alloc().directBuffer()));
    ps = new PrintStream(this, false);
    targetCtx = channel.pipeline().context((this.isStdOut ? "out" : "err"));
}