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


Java ServletOutputStream类代码示例

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


ServletOutputStream类属于javax.servlet包,在下文中一共展示了ServletOutputStream类的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: 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

示例3: 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

示例4: updateResponse

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
private void updateResponse(String requestURI, ContentCachingResponseWrapper responseWrapper) throws IOException {
	try {
		HttpServletResponse rawResponse = (HttpServletResponse) responseWrapper.getResponse();
		byte[] body = responseWrapper.getContentAsByteArray();
		ServletOutputStream outputStream = rawResponse.getOutputStream();
		if (rawResponse.isCommitted()) {
			if (body.length > 0) {
				StreamUtils.copy(body, outputStream);
			}
		} else {
			if (body.length > 0) {
				rawResponse.setContentLength(body.length);
				StreamUtils.copy(body, rawResponse.getOutputStream());
			}
		}
		finishResponse(outputStream, body);
	} catch (Exception ex) {
		logger.error("请求地址为" + requestURI + "的连接返回报文失败,原因是{}", ex.getMessage());
	}
}
 
开发者ID:wengwh,项目名称:plumdo-stock,代码行数:21,代码来源:RequestLogFilter.java

示例5: exportExcel

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
/**
    * Exports tool results into excel.
    * 
    * @throws IOException
    */
   private ActionForward exportExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException {

initializeScratchieService();
String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE);

LinkedHashMap<String, ExcelCell[][]> dataToExport = service.exportExcel(scratchie.getContentId());

String fileName = "scratchie_export.xlsx";
fileName = FileUtil.encodeFilenameForDownload(request, fileName);

response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);

// set cookie that will tell JS script that export has been finished
String downloadTokenValue = WebUtil.readStrParam(request, "downloadTokenValue");
Cookie fileDownloadTokenCookie = new Cookie("fileDownloadToken", downloadTokenValue);
fileDownloadTokenCookie.setPath("/");
response.addCookie(fileDownloadTokenCookie);

// Code to generate file and write file contents to response
ServletOutputStream out = response.getOutputStream();
ExcelUtil.createExcel(out, dataToExport, null, false);

return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:MonitoringAction.java

示例6: captcha

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response) throws ServletException, IOException {
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setContentType("image/jpeg");

    //生成文字验证码
    String text = producer.createText();
    //生成图片验证码
    BufferedImage image = producer.createImage(text);
    //保存到shiro session
    ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);

    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(image, "jpg", out);
    IOUtils.closeQuietly(out);


}
 
开发者ID:davichi11,项目名称:my-spring-boot-project,代码行数:19,代码来源:SysLoginController.java

示例7: exportReservationsCsv

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@RequestMapping(value = Mappings.ADMINISTRATION_EXPORT_RESERVATIONS_CSV, method = RequestMethod.GET)
public void exportReservationsCsv(
        @RequestParam("begin") String begin,
        @RequestParam("end") String end,
        HttpServletResponse response) throws Exception {

    Date beginDate = Utils.stringToDate(begin);
    Date endDate = Utils.stringToDate(end);

    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment; filename=\"export.csv\"");

    File tempFile = exportService.exportReserationsCsv(beginDate, endDate);

    try (ServletOutputStream out = response.getOutputStream();
         InputStream in = Files.newInputStream(tempFile.toPath())) {
        IOUtils.copy(in, out);
    }

    Files.delete(tempFile.toPath());

}
 
开发者ID:remipassmoilesel,项目名称:simple-hostel-management,代码行数:23,代码来源:AdministrationController.java

示例8: 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

示例9: copyRange

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param istream The input stream to read from
 * @param ostream The output stream to write to
 * @return Exception which occurred during processing
 */
private IOException copyRange(InputStream istream,
                              ServletOutputStream ostream) {

    // Copy the input stream to the output stream
    IOException exception = null;
    byte buffer[] = new byte[input];
    int len = buffer.length;
    while (true) {
        try {
            len = istream.read(buffer);
            if (len == -1)
                break;
            ostream.write(buffer, 0, len);
        } catch (IOException e) {
            exception = e;
            len = -1;
            break;
        }
    }
    return exception;

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:32,代码来源:DefaultServlet.java

示例10: captcha

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
	response.setHeader("Cache-Control", "no-store, no-cache");
	response.setContentType("image/jpeg");

	//生成文字验证码
	String text = producer.createText();
	//生成图片验证码
	BufferedImage image = producer.createImage(text);
	//保存到shiro session
	ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);

	ServletOutputStream out = response.getOutputStream();
	ImageIO.write(image, "jpg", out);
	IOUtils.closeQuietly(out);
}
 
开发者ID:zhaoqicheng,项目名称:renren-fast,代码行数:17,代码来源:SysLoginController.java

示例11: getAttachmentContent

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@RequestMapping(value = "/email/attachment/{id}",method = RequestMethod.GET)
public void getAttachmentContent(@PathVariable("id") Long id, HttpServletResponse response) {

	final AttachmentEntity attachment = attachmentService.findAttachmentById(id);

	if (attachment != null) {
		try {
			ServletOutputStream stream = response.getOutputStream();
			OutputStream out = new BufferedOutputStream(stream);

			response.resetBuffer();
			response.setBufferSize(attachment.getAttachmentContent().getData().length);
			response.setHeader("Content-Length", String.valueOf(attachment.
                       getAttachmentContent().getData().length));

			out.write(attachment.getAttachmentContent().getData());

			out.close();
			stream.close();
		} catch (final IOException e) {
			log.error("Unable to open file", e);
		}
	} else {
		log.error("File does not exist");
	}
}
 
开发者ID:dopse,项目名称:maildump,代码行数:27,代码来源:EmailController.java

示例12: startJob

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@RequestMapping(value="/launchjob")
@ResponseBody
public void startJob(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {

    log.info("manual startJob");
    try {
        httpServletResponse.setContentType("text/plain; charset=utf-8");
        ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
        if(scheduleJobs.getJobStatus() == ScheduleJobs.JOB_STATUS_RUNNING) {
            responseOutputStream.write("Job正在运行。。。".getBytes("utf-8"));
            responseOutputStream.flush();
            responseOutputStream.close();
        } else {
            log.info("scheduleJobs.cronJob() start by controller...");
            scheduleJobs.cronJob();
        }
    } catch (Exception e) {
        log.info("startJob exception e="+e.getMessage());
    }
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:21,代码来源:CommonController.java

示例13: doPost

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	req.setCharacterEncoding("utf-8");
	resp.setCharacterEncoding("utf-8");
	HashMap<String, Object> status = new HashMap<>();
	JSONObject object = new JSONObject();
	String quizFormName = req.getParameter("name");
	// get main data
	QuizForm qf = allQuizForm.get(quizFormName);
	// build status
	status.put("code", String.valueOf(HttpServletResponse.SC_OK));
	status.put("message", "query quiz form successful");
	status.put("extra", Constant.JSON.EMPTY_OBJECT);
	status.put("security", Constant.JSON.EMPTY_OBJECT);
	// build main object
	object.put("meta", status);
	object.put("data", qf);
	// FIXME 非测试时移去注释 (配合Configuration System把这里设计的合理一点 - 磷)
	// response.setContentType("application/json"); // specific content type
	try (ServletOutputStream out = resp.getOutputStream()) {
		out.write(resp.toString().getBytes(StandardCharsets.UTF_8));
		out.flush();
	} catch (IOException e) {
		LoggerFactory.getLogger(Counter.class).error("IOException thrown: ", e);
	}
}
 
开发者ID:ProgramLeague,项目名称:strictfp-back-end,代码行数:27,代码来源:GetQuiz.java

示例14: 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

示例15: doService

import javax.servlet.ServletOutputStream; //导入依赖的package包/类
private void doService(HttpMethod method, HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    outputRequestLog(req);

    InputStream iStream = null;
    ServletOutputStream oStream = null;
    try {
        long threadID = Thread.currentThread().getId();
        log.debug("[" + threadID + "] forwarded to " + distributer.getRedirectUrl(req));
        HttpClient client = new HttpClient();
        log.debug("[" + threadID + "]send request.");
        int resultCode = client.executeMethod(method);
        log.debug("[" + threadID + "]got response: result code is " + resultCode);
        res.setStatus(resultCode);
        for (Header header : method.getResponseHeaders()) {
            res.setHeader(header.getName(), header.getValue());
        }
        iStream = method.getResponseBodyAsStream();
        oStream = res.getOutputStream();

        writeOutputStream(iStream, oStream);

        log.debug("[" + threadID + "] response sent to client.");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    } finally {
        if (iStream != null) {
            iStream.close();
        }
        if (oStream != null) {
            oStream.close();
        }
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:36,代码来源:ForwarderServlet.java


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