use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project jersey by jersey.
the class JerseyServerHandler method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpRequest) {
final HttpRequest req = (HttpRequest) msg;
if (HttpUtil.is100ContinueExpected(req)) {
ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
}
// clearing the content - possible leftover from previous request processing.
isList.clear();
final ContainerRequest requestContext = createContainerRequest(ctx, req);
requestContext.setWriter(new NettyResponseWriter(ctx, req, container));
// must be like this, since there is a blocking read from Jersey
container.getExecutorService().execute(new Runnable() {
@Override
public void run() {
container.getApplicationHandler().handle(requestContext);
}
});
}
if (msg instanceof HttpContent) {
HttpContent httpContent = (HttpContent) msg;
ByteBuf content = httpContent.content();
if (content.isReadable()) {
isList.add(new ByteBufInputStream(content));
}
if (msg instanceof LastHttpContent) {
isList.add(NettyInputStream.END_OF_INPUT);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project ratpack by ratpack.
the class DefaultSession method hydrate.
private void hydrate(ByteBuf bytes) throws Exception {
if (bytes.readableBytes() > 0) {
SerializedForm deserialized = defaultSerializer.deserialize(SerializedForm.class, new ByteBufInputStream(bytes));
entries = deserialized.entries;
} else {
this.entries = new HashMap<>();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project rskj by rsksmart.
the class JsonRpcWeb3ServerHandler method processRequest.
private HttpResponse processRequest(FullHttpRequest request) throws JsonProcessingException {
HttpResponse response;
ByteBuf responseContent = Unpooled.buffer();
HttpResponseStatus responseStatus = HttpResponseStatus.OK;
try (ByteBufOutputStream os = new ByteBufOutputStream(responseContent);
ByteBufInputStream is = new ByteBufInputStream(request.content().retain())) {
int result = jsonRpcServer.handleRequest(is, os);
responseStatus = HttpResponseStatus.valueOf(DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result));
} catch (Exception e) {
LOGGER.error("Unexpected error", e);
responseContent = buildErrorContent(JSON_RPC_SERVER_ERROR_HIGH_CODE, HttpResponseStatus.INTERNAL_SERVER_ERROR.reasonPhrase());
responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
} finally {
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, responseStatus, responseContent);
}
return response;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project bookkeeper by apache.
the class LedgerEntry method getEntryInputStream.
/**
* Returns the content of the entry.
* This method can be called only once. While using v2 wire protocol this method will automatically release
* the internal ByteBuf when calling the close
* method of the returned InputStream
*
* @return an InputStream which gives access to the content of the entry
* @throws IllegalStateException if this method is called twice
*/
public InputStream getEntryInputStream() {
checkState(null != data, "entry content can be accessed only once");
ByteBufInputStream res = new ByteBufInputStream(data);
data = null;
return res;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project jocean-http by isdom.
the class Nettys method dumpByteBufAsBytes.
public static byte[] dumpByteBufAsBytes(final ByteBuf bytebuf) throws IOException {
try (final InputStream is = new ByteBufInputStream(bytebuf)) {
final byte[] bytes = new byte[is.available()];
is.read(bytes);
return bytes;
}
}
Aggregations