本文整理汇总了Java中io.reactivex.netty.protocol.http.server.HttpServerResponse.flush方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.flush方法的具体用法?Java HttpServerResponse.flush怎么用?Java HttpServerResponse.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.netty.protocol.http.server.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
String uri = request.getUri();
if (uri.startsWith("test/singleEntity")) {
return handleSingleEntity(response);
} else if (uri.startsWith("test/stream")) {
return handleStream(response);
} else if (uri.startsWith("test/nochunk_stream")) {
return handleStreamWithoutChunking(response);
} else if (uri.startsWith("test/largeStream")) {
return handleLargeStream(response);
} else if (uri.startsWith("test/timeout")) {
return simulateTimeout(request, response);
} else if (uri.startsWith("test/post")) {
return handlePost(request, response);
} else {
response.setStatus(HttpResponseStatus.NOT_FOUND);
return response.flush();
}
}
示例2: handleStreamWithoutChunking
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public Observable<Void> handleStreamWithoutChunking(HttpServerResponse<ByteBuf> response) {
response.getHeaders().add(HttpHeaders.Names.CONTENT_TYPE, "text/event-stream");
for (String contentPart : smallStreamContent) {
response.writeString("data:");
response.writeString(contentPart);
response.writeString("\n\n");
}
return response.flush();
}
示例3: sendStreamingResponse
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private static Observable<Void> sendStreamingResponse(HttpServerResponse<ByteBuf> response, List<String> data) {
response.getHeaders().add(HttpHeaders.Names.CONTENT_TYPE, "text/event-stream");
response.getHeaders().add(HttpHeaders.Names.TRANSFER_ENCODING, "chunked");
for (String line : data) {
byte[] contentBytes = ("data:" + line + "\n\n").getBytes();
response.writeBytes(contentBytes);
}
return response.flush();
}