当前位置: 首页>>代码示例>>Java>>正文


Java HttpServerResponse.writeBytes方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:jscattergood,项目名称:WeatherAlarm,代码行数:25,代码来源:WeatherAlarmEndpoint.java

示例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;
}
 
开发者ID:jscattergood,项目名称:WeatherAlarm,代码行数:11,代码来源:TestUtils.java

示例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);
  }
}
 
开发者ID:adrobisch,项目名称:nibbler,代码行数:8,代码来源:NettyResponseWriter.java

示例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();
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:11,代码来源:RequestProcessor.java


注:本文中的io.reactivex.netty.protocol.http.server.HttpServerResponse.writeBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。