當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。