本文整理汇总了Java中io.reactivex.netty.protocol.http.server.HttpServerResponse.writeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.writeBytes方法的具体用法?Java HttpServerResponse.writeBytes怎么用?Java HttpServerResponse.writeBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.netty.protocol.http.server.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.writeBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGet
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private void handleGet(HttpServerResponse<ByteBuf> response, String uri) {
String[] parts = uri.substring(1).split("/");
ObjectMapper mapper = new ObjectMapper();
try {
if (parts.length == 1) {
response.writeBytes(mapper.writeValueAsBytes(alarmService.getAlarms()));
} else if (parts.length == 2) {
String alarmName = URLDecoder.decode(parts[1], "UTF-8");
WeatherAlarm alarm = alarmService.getAlarm(alarmName);
if (alarm != null) {
response.writeBytes(mapper.writeValueAsBytes(alarm));
} else {
logger.debug("No alarm found with name " + alarmName);
response.setStatus(HttpResponseStatus.NOT_FOUND);
}
} else {
logger.error("Unsupported resource request " + uri);
response.setStatus(HttpResponseStatus.NOT_FOUND);
}
} catch (IOException e) {
logger.error("Failed to write JSON to response", e);
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
示例2: createMockHttpResponse
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static HttpServerResponse<ByteBuf> createMockHttpResponse(Capture<HttpResponseStatus> captureResponseStatus,
Capture<byte[]> captureWrittenBytes) {
HttpServerResponse<ByteBuf> mockResponse = EasyMock.createMock(HttpServerResponse.class);
mockResponse.writeBytes(EasyMock.capture(captureWrittenBytes));
mockResponse.setStatus(EasyMock.capture(captureResponseStatus));
EasyMock.expect(mockResponse.close()).andReturn(Observable.empty()).anyTimes();
EasyMock.replay(mockResponse);
return mockResponse;
}
示例3: writeToResponse
import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private void writeToResponse(HttpServerResponse<ByteBuf> response, Optional<TypedOutput> typedOutput) {
if (typedOutput.isPresent()) {
response.writeBytes(typedOutput.get().getOutput());
String contentType = typedOutput.get().getMediaType().orElse(MediaType.APPLICATION_OCTET_STREAM).contentType();
response.getHeaders().set(Header.ContentType.name(), contentType);
}
}
示例4: 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();
}