Example usage for io.netty.buffer ByteBufInputStream ByteBufInputStream

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

Introduction

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

Prototype

public ByteBufInputStream(ByteBuf buffer) 

Source Link

Document

Creates a new stream which reads data from the specified buffer starting at the current readerIndex and ending at the current writerIndex .

Usage

From source file:com.myseti.framework.monitor.net.DecodeProtocol.java

@Override
protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {

    if (bb.readableBytes() < Utility.PACKAGE_LENGTH) {
        return;// www. j a v a 2s . c  o m
    } else {

        bb.markReaderIndex();
        ByteBufInputStream stream = new ByteBufInputStream(bb);
        try {
            byte[] len = new byte[4];
            stream.read(len, 0, 4);
            int length = com.myseti.framework.core.HexTools.byte2Int(len);
            System.out.print("" + length + "\n");
            byte[] result = new byte[length - 4];
            stream.read(result, 0, length - 4);
            ProtocolEntity entity = new ProtocolEntity(result);
            list.add(entity);
            System.out.print("DecodeProtocol active! add a new entity \n");
        } catch (Exception ex) {
            System.out.print(ex.toString());
        }
    }

}

From source file:com.netflix.client.netty.http.NettyClientTest.java

License:Apache License

private static Observable<Person> getPersonObservable(Observable<HttpClientResponse<ByteBuf>> response) {
    return response.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>() {
        @Override//from   w  ww. j  a  v a 2s . c o  m
        public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> t1) {
            return t1.getContent();
        }

    }).map(new Func1<ByteBuf, Person>() {
        @Override
        public Person call(ByteBuf t1) {
            try {
                return JacksonCodec.<Person>getInstance().deserialize(new ByteBufInputStream(t1),
                        TypeDef.fromClass(Person.class));
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    });
}

From source file:com.netflix.recipes.rss.netty.NettyHandlerContainer.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws URISyntaxException, IOException {
    if (msg instanceof FullHttpRequest) {
        FullHttpRequest httpRequest = (FullHttpRequest) msg;
        String base = getBaseUri(httpRequest);
        URI baseUri = new URI(base);
        URI requestUri = new URI(base.substring(0, base.length() - 1) + httpRequest.getUri());
        ContainerRequest cRequest = new ContainerRequest(application, httpRequest.getMethod().name(), baseUri,
                requestUri, getHeaders(httpRequest), new ByteBufInputStream(httpRequest.content()));
        application.handleRequest(cRequest, new Writer(ctx));
    }/*from  ww  w  .jav a  2s. c o  m*/
}

From source file:com.ning.http.client.providers.netty_4.NettyResponse.java

License:Apache License

public InputStream getResponseBodyAsStream() throws IOException {
    return new ByteBufInputStream(getResponseBodyAsByteBuf());
}

From source file:com.openddal.server.ProtocolTransport.java

License:Apache License

public ProtocolTransport(Channel channel, ByteBuf in) {
    this.channel = channel;
    this.in = in;
    out = channel.alloc().buffer(DEFAULT_BUFFER_SIZE);
    input = new ByteBufInputStream(in);
    output = new ByteBufOutputStream(out);
}

From source file:com.soho.framework.server.servlet.impl.ServletInputStreamImpl.java

License:Apache License

public ServletInputStreamImpl(FullHttpRequest request) {
    this.request = request;

    this.in = new ByteBufInputStream(request.content());
}

From source file:com.soho.framework.server.servlet.impl.ServletInputStreamImpl.java

License:Apache License

public ServletInputStreamImpl(HttpRequest request) {
    this.request = request;

    this.in = new ByteBufInputStream(Unpooled.buffer(0));
}

From source file:com.spotify.ffwd.http.HttpDecoder.java

License:Apache License

private void postBatch(final ChannelHandlerContext ctx, final FullHttpRequest in, final List<Object> out) {
    final Batch batch;
    try (final InputStream inputStream = new ByteBufInputStream(in.content())) {
        batch = mapper.readValue(inputStream, Batch.class);
    } catch (final IOException e) {
        log.error("HTTP Bad Request", e);
        throw new HttpException(HttpResponseStatus.BAD_REQUEST);
    }/* w w w .  ja va2s  .  c o m*/

    out.add(batch);

    ctx.channel().writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK))
            .addListener((ChannelFutureListener) future -> future.channel());
}

From source file:com.spotify.ffwd.json.JsonObjectMapperDecoder.java

License:Apache License

private Object decode0(ByteBuf in, List<Object> out) throws IOException, JsonProcessingException {
    final JsonNode tree;

    try (final InputStream input = new ByteBufInputStream(in)) {
        tree = mapper.readTree(input);//from  w  w w . jav a  2s  .c  o  m
    }

    final JsonNode typeNode = tree.get("type");

    if (typeNode == null) {
        throw new IllegalArgumentException("Missing field 'type'");
    }

    final String type = typeNode.asText();

    if ("event".equals(type)) {
        return decodeEvent(tree, out);
    }

    if ("metric".equals(type)) {
        return decodeMetric(tree, out);
    }

    throw new IllegalArgumentException("Invalid metric type '" + type + "'");
}

From source file:com.spotify.ffwd.protobuf.ProtobufDecoder.java

License:Apache License

private Object decodeFrame0(ByteBuf buffer) throws Exception {
    final Protocol0.Message message;

    final InputStream inputStream = new ByteBufInputStream(buffer);

    try {/* www.  j ava  2 s. co m*/
        message = Protocol0.Message.parseFrom(inputStream);
    } catch (final InvalidProtocolBufferException e) {
        throw new Exception("Invalid protobuf message", e);
    }

    if (message.hasEvent()) {
        return decodeEvent0(message.getEvent());
    }

    if (message.hasMetric()) {
        return decodeMetric0(message.getMetric());
    }

    return null;
}