當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletOutputStream.flush方法代碼示例

本文整理匯總了Java中javax.servlet.ServletOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletOutputStream.flush方法的具體用法?Java ServletOutputStream.flush怎麽用?Java ServletOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.ServletOutputStream的用法示例。


在下文中一共展示了ServletOutputStream.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verify

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * 生成驗證碼的邏輯
 */
@RequestMapping("verify")
private ModelAndView verify(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession();
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");
    String capText = captchaProducer.createText();
    session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
    BufferedImage bi = captchaProducer.createImage(capText);
    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(bi, "jpg", out);
    try {
        out.flush();
    } finally {
        out.close();
    }
    return null;
}
 
開發者ID:cx118118,項目名稱:ssm-rbac,代碼行數:24,代碼來源:PublicController.java

示例2: writeToResponse

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Write the given temporary OutputStream to the HTTP response.
 * @param response current HTTP response
 * @param baos the temporary OutputStream to write
 * @throws IOException if writing/flushing failed
 */
protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException {
    // Write content type and also length (determined via byte array).
    response.setContentType(getContentType());
    response.setContentLength(baos.size());

    // Flush byte array to servlet output stream.
    ServletOutputStream out = response.getOutputStream();
    baos.writeTo(out);
    out.flush();
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:17,代碼來源:AbstractView.java

示例3: writeResponse

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
protected void writeResponse(Response res) throws Exception {
    response.setStatus(res.getStatusCode(), res.getStatusMessage());
    for (HeaderField header : res.getHeader().getAllHeaderFields()) {
        if (header.getHeaderName().equals(Header.TRANSFER_ENCODING))
            continue;
        response.addHeader(header.getHeaderName().toString(), header.getValue());
    }

    ServletOutputStream out = response.getOutputStream();
    res.getBody().write(new PlainBodyTransferrer(out));
    out.flush();

    response.flushBuffer();

    exchange.setTimeResSent(System.currentTimeMillis());
    exchange.collectStatistics();
}
 
開發者ID:membrane,項目名稱:membrane-spring-boot-starter,代碼行數:19,代碼來源:HttpServletHandler.java

示例4: image

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * 驗證碼
 */
@RequestMapping(value = "/captcha", method = RequestMethod.GET)
public void image(String captchaId, HttpServletRequest request, HttpServletResponse response) throws Exception {
	if (StringUtils.isEmpty(captchaId)) {
		captchaId = request.getSession().getId();
	}
	response.addHeader("vincent.li", "vincent.li");
	response.setHeader("Pragma", "no-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Cache-Control", "no-store");
	response.setDateHeader("Expires", 0);
	response.setContentType("image/jpeg");

	ServletOutputStream servletOutputStream = null;
	try {
		servletOutputStream = response.getOutputStream();
		BufferedImage bufferedImage = (BufferedImage) imageCaptchaService.getChallengeForID(captchaId);
		ImageIO.write(bufferedImage, "jpg", servletOutputStream);
		servletOutputStream.flush();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		IOUtils.closeQuietly(servletOutputStream);
	}
}
 
開發者ID:wenjian-li,項目名稱:spring_mybatis_shiro,代碼行數:28,代碼來源:CommonController.java

示例5: generate

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * 生成驗證碼
 */
static void generate(HttpServletResponse response, String vCode) {
	BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
	response.setHeader("Pragma","no-cache");
	response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires", 0);
	response.setContentType("image/jpeg");
	
	ServletOutputStream sos = null;
	try {
		drawGraphic(image, vCode);
		sos = response.getOutputStream();
		ImageIO.write(image, "JPEG", sos);
		sos.flush();
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		IOUtils.closeQuietly(sos);
	}
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:23,代碼來源:CaptchaUtils.java

示例6: doHandleRequest

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
protected ModelAndView doHandleRequest(HttpServletRequest req,
		HttpServletResponse res) throws Exception {
	String id = req.getParameter(ID_KEY);
	if (!StringUtils.hasText(id)) {
		id = (String) req.getAttribute(ID_KEY);
	}
	if (StringUtils.isEmpty(id)) {
		throw new RuntimeException("Upload definition id can not be null!");
	}
	UploadDefinition definition = fileService.getUploadDefinition(id);
	if (StringUtils.isEmpty(definition.getUploadProcessorKey())) {
		throw new RuntimeException("Upload definition [" + id
				+ "] has not set processor!");
	}
	InputStream in = fileService.getFile(definition);
	BufferedInputStream bin = new BufferedInputStream(in);
	ServletOutputStream out = res.getOutputStream();
	try {
		IOUtils.copy(bin, out);
	} finally {
		IOUtils.closeQuietly(in);
	}
	out.flush();
	out.close();
	return null;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:28,代碼來源:ProcessDisplayController.java

示例7: doFilter

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
		FilterChain arg2) throws IOException, ServletException {
	
	if(AuthUtil.getAuthFlag()){
		 arg2.doFilter(arg0, arg1);
		 return ;
	}
	
	try{
		 HttpServletRequest request  = (HttpServletRequest) arg0;
	    WrapperResponse wrapper = new WrapperResponse((HttpServletResponse)arg1);
		boolean flag =  doGet(request, wrapper);
		log.info("HTTPAuthFilter uri {} doGet flag : {}",request.getRequestURI(),flag);
		if(flag){
			    arg2.doFilter(arg0, wrapper);
			    byte[] content = wrapper.getContent();
			    content = filterGroups(request, content);
                   if(ArrayUtils.isNotEmpty(content)){
                       ServletOutputStream out = arg1.getOutputStream();
    			        out.write(content);
    			        out.flush();
    			        out.close();
                   }
		}
	}catch(Exception e){
		log.error(e.getMessage(),e);
	}finally{
		AuthUtil.THREAD_LOCAL_USER.remove();
	}
	
}
 
開發者ID:xiaomin0322,項目名稱:marathon-auth-plugin,代碼行數:33,代碼來源:HTTPAuthFilter.java

示例8: execute

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
public String execute() throws Exception {
		HttpServletRequest request = Struts2Utils.getRequest();
		HttpServletResponse response = Struts2Utils.getResponse();
        ByteArrayOutputStream out = null;
        byte[] captchaChallengeAsJpeg = null;  
        // the output stream to render the captcha image as jpeg into  
        ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();  
        try {  
            // get the session id that will identify the generated captcha.  
            // the same id must be used to validate the response, the session id  
            // is a good candidate!  
            String captchaId = request.getSession().getId();  
            // call the ImageCaptchaService getChallenge method  
            BufferedImage challenge = imageCaptchaService.getImageChallengeForID(captchaId, request.getLocale());
            // a jpeg encoder
/*** jdk1.7之後默認不支持了 **/
//            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
//            jpegEncoder.encode(challenge);

//            換成新版圖片api
            ImageIO.write(challenge, "jpg", jpegOutputStream);

        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }
        captchaChallengeAsJpeg = jpegOutputStream.toByteArray();    
        // flush it in the response    
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        ServletOutputStream responseOutputStream = response.getOutputStream();
        responseOutputStream.write(captchaChallengeAsJpeg);
        responseOutputStream.flush();
        responseOutputStream.close();
        return null;
	}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:39,代碼來源:JcaptchaAction.java

示例9: getVerifyCodeImage

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@RequestMapping("/captcha")
public void getVerifyCodeImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
  HttpSession session = request.getSession();
   
       response.setDateHeader("Expires", 0);  
        
      // Set standard HTTP/1.1 no-cache headers.  
   response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");  
     // Set IE extended HTTP/1.1 no-cache headers (use addHeader).  
       response.addHeader("Cache-Control", "post-check=0, pre-check=0");  
         // Set standard HTTP/1.0 no-cache header.  
         response.setHeader("Pragma", "no-cache");  
      // return a jpeg  
        response.setContentType("image/jpeg");  
    // create the text for the image  
 String capText = captchaProducer.createText();  
   // store the text in the session  
   session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);  
      // create the image with the text  
          BufferedImage bi = captchaProducer.createImage(capText);  
     ServletOutputStream out = response.getOutputStream();  
          
   // write the data out  
       ImageIO.write(bi, "jpg", out);  
      try {  
         out.flush();  
       } finally {  
             out.close();  
        }  
      String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);  
     System.out.println("******************驗證碼是: " + code + "******************");  
}
 
開發者ID:ranji1221,項目名稱:clemon,代碼行數:33,代碼來源:ValidateCodeController.java

示例10: writeImageCaptcha

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void writeImageCaptcha(HttpServletResponse response,String capText) throws IOException {
    // 設置請求頭
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control",
            "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");
    // 寫出圖片流
    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(defaultKaptcha.createImage(capText),"jpg",out);
    out.flush();
}
 
開發者ID:Nbsaw,項目名稱:miaohu,代碼行數:14,代碼來源:CaptchaServiceImpl.java

示例11: writeBodyBytes

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void writeBodyBytes(byte[] bytes) {
  try {
    headerContentLength(bytes.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(bytes);
    out.flush();
  } catch (IOException e) {
    throw new RuntimeException("Couldn't send body: "+e.getMessage(), e);
  }
}
 
開發者ID:rockscript,項目名稱:rockscript,代碼行數:11,代碼來源:ServerResponse.java

示例12: testLongProcess

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Verify that the test result can be returned correctly even when the
 * logic in the method to test takes a long time and thus it verifies that
 * the test result is only returned after it has been written in the
 * application scope on the server side.
 */
public void testLongProcess() throws Exception
{
    ServletOutputStream os = response.getOutputStream();
    os.print("<html><head><Long Process></head><body>");
    os.flush();

    // do some processing that takes a while ...
    Thread.sleep(3000);
    os.println("Some data</body></html>");
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:17,代碼來源:TestServletTestCase_TestResult.java

示例13: getVerifyCodeImage

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@RequestMapping("/captcha")
public void getVerifyCodeImage(HttpServletRequest request, HttpServletResponse response) throws Exception {
	HttpSession session = request.getSession();

	response.setDateHeader("Expires", 0);
	//-- Set standard HTTP/1.1 no-cache headers.
	response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	//-- Set IE extended HTTP/1.1 no-cache headers (use addHeader).
	response.addHeader("Cache-Control", "post-check=0, pre-check=0");
	//-- Set standard HTTP/1.0 no-cache header.
	response.setHeader("Pragma", "no-cache");
	//-- return a jpeg
	response.setContentType("image/jpeg");
	//-- create the text for the image
	String capText = captchaProducer.createText();
	//-- store the text in the session
	session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
	//-- create the image with the text
	BufferedImage bi = captchaProducer.createImage(capText);
	ServletOutputStream out = response.getOutputStream();

	//-- write the data out
	ImageIO.write(bi, "jpg", out);
	try {
		out.flush();
	} finally {
		out.close();
	}
}
 
開發者ID:ranji1221,項目名稱:lemcloud,代碼行數:30,代碼來源:CaptchaResource.java

示例14: contextInitialized

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
public void contextInitialized(ServletContextEvent sce) {
  Map<String, AsyncContext> notificationStreams = new ConcurrentHashMap<String, AsyncContext>();
  sce.getServletContext().setAttribute("notificationStreams", notificationStreams);
  Thread thread = new Thread(new Runnable(){

@Override
public void run() {
	String clientId = null;
	AsyncContext asyncContext = null;
	while(true)
	   {
		   try {
			   Map.Entry<String, String> entry = blockingQueue.take();
			   clientId = entry.getKey();
			   asyncContext = notificationStreams.get(clientId);
			   if(notificationStreams.get(entry.getKey()) != null){
				   ServletOutputStream out = asyncContext.getResponse().getOutputStream();
				   out.write(entry.getValue().getBytes());
				   out.flush();
				   asyncContext.getResponse().flushBuffer();
			   }
		   } catch (Exception e){
			   ErrorLog.logError("Cannot write to client",	e.getStackTrace());
			   asyncContext.complete();
			   notificationStreams.remove(clientId);
			   break;
		   }
	   }
}

  });
  thread.start();

 }
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:35,代碼來源:NotificationService.java

示例15: doGet

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    Spider s=new GithubCrawler().createSpider();
    SpiderManager.get().add(s);
    out.write(("add spider of "+s.getName()).getBytes());
    out.flush();
    out.close();
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:11,代碼來源:HelloServlet.java


注:本文中的javax.servlet.ServletOutputStream.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。