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


Java ServletOutputStream.setWriteListener方法代码示例

本文整理汇总了Java中javax.servlet.ServletOutputStream.setWriteListener方法的典型用法代码示例。如果您正苦于以下问题:Java ServletOutputStream.setWriteListener方法的具体用法?Java ServletOutputStream.setWriteListener怎么用?Java ServletOutputStream.setWriteListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletOutputStream的用法示例。


在下文中一共展示了ServletOutputStream.setWriteListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOutputStream

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
public ServletOutputStream getOutputStream() throws IOException {

  final ServletOutputStream outputStream = d.getOutputStream();
  return new ServletOutputStream() {

    @Override
    public void write(int b) throws IOException {
      respBody.write(b);
      outputStream.write(b);
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {
      outputStream.setWriteListener(writeListener);
    }

    @Override
    public boolean isReady() {
      return outputStream.isReady();
    }
  };
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:AccessLogFilter.java

示例2: processRequest

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");

	AsyncContext context = request.startAsync();
	ServletOutputStream output = response.getOutputStream();
	output.setWriteListener(new WritingListener(output, context));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:9,代码来源:WritingServlet.java

示例3: handle

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
public void handle(String path, Request request, final HttpServletRequest servletRequest,
		final HttpServletResponse servletResponse) throws IOException, ServletException {
	request.setHandled(true);
	switch (path) {
	case "/hello":
		servletResponse.setStatus(200);
		servletResponse.setContentType("text/plain");
		servletResponse.getWriter().write("Hello World!");
		break;
	case "/hello-async":
		final AsyncContext context = request.startAsync();
		Thread t = new Thread(() -> {
			servletResponse.setStatus(200);
			servletResponse.setContentType("text/plain");
			final ServletOutputStream outputStream;
			try {
				outputStream = servletResponse.getOutputStream();
				outputStream.setWriteListener(new WriteListener() {
					@Override
					public void onWritePossible() throws IOException {
						PrintWriter w = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"));
						w.write("Hello World!");
						w.close();
						context.complete();
					}

					@Override
					public void onError(Throwable throwable) {
						context.complete();
					}
				});
			} catch (IOException e) {
				context.complete();
			}
		});
		t.start();
		break;
	default:
		servletResponse.setStatus(404);
		servletResponse.setContentType("text/plain");
		servletResponse.getWriter().write("Not found.");
		break;
	}
}
 
开发者ID:mevdschee,项目名称:tqdev-metrics,代码行数:46,代码来源:HelloWorldHandler.java


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