本文整理汇总了Java中io.reactivex.netty.protocol.http.server.HttpServerResponse.writeAndFlush方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.writeAndFlush方法的具体用法?Java HttpServerResponse.writeAndFlush怎么用?Java HttpServerResponse.writeAndFlush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.netty.protocol.http.server.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.writeAndFlush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bridgeResponse
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
ContainerResponseWriter bridgeResponse(final HttpServerResponse<ByteBuf> serverResponse) {
return new ContainerResponseWriter() {
private final ByteBuf contentBuffer = serverResponse.getChannel().alloc().buffer();
@Override
public OutputStream writeStatusAndHeaders(long contentLength, ContainerResponse response) {
int responseStatus = response.getStatus();
serverResponse.setStatus(HttpResponseStatus.valueOf(responseStatus));
HttpResponseHeaders responseHeaders = serverResponse.getHeaders();
for(Map.Entry<String, List<Object>> header : response.getHttpHeaders().entrySet()){
responseHeaders.setHeader(header.getKey(), header.getValue());
}
return new ByteBufOutputStream(contentBuffer);
}
@Override
public void finish() {
serverResponse.writeAndFlush(contentBuffer);
}
};
}
示例2: writeMetric
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void writeMetric(String json, HttpServerResponse<O> response) {
byte[] bytes = json.getBytes(Charset.defaultCharset());
ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length + EXTRA_SPACE);
byteBuf.writeBytes(HEADER);
byteBuf.writeBytes(bytes);
byteBuf.writeBytes(FOOTER);
response.writeAndFlush((O) byteBuf);
}
示例3: handle
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public Observable<Void> handle(HttpServerRequest request, HttpServerResponse response) {
if (request.getPath().startsWith("/hystrix.stream")) {
return new HystrixMetricsStreamHandler(this).handle(request, response);
}
return response.writeAndFlush(routeRequest(request, response).toBlocking().first().toString() );
}