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


Java ServletResponse.getOutputStream方法代码示例

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


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

示例1: service

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void service(ServletRequest servletRequest, ServletResponse response) throws ServletException, IOException {
  ClientSettings settings = new ClientSettings(
      options.getOption(SupportService.SUPPORT_EMAIL_ADDR),
      options.getOption(SupportService.SUPPORT_EMAIL_SUBJECT),
      options.getOption(SupportService.OUTSIDE_COMMUNICATION_DISABLED),
      options.getOption(AccelerationOptions.ENABLE_SUBHOUR_POLICIES),
      options.getOption(UIOptions.ALLOW_LOWER_PROVISIONING_SETTINGS),
      options.getOption(UIOptions.TABLEAU_TDS_MIMETYPE));

  String environment = config.allowTestApis ? "DEVELOPMENT" : "PRODUCTION";
  final ServerData indexConfig = new ServerData(environment, serverHealthMonitor, config.getConfig(), settings, getVersionInfo(), supportService.getClusterId().getIdentity());

  Template tmp = templateCfg.getTemplate("/index.html");

  response.setContentType("text/html; charset=utf-8");
  OutputStreamWriter outputWriter = new OutputStreamWriter(response.getOutputStream());
  try {
    tmp.process(ImmutableMap.of("dremio", indexConfig), outputWriter);
    outputWriter.flush();
    outputWriter.close();
  } catch (TemplateException e) {
    throw new IOException("Error rendering index.html template", e);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:IndexServlet.java

示例2: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * Perform the filter function. Called by the container upon a request
 * matching the filter pattern defined in <code>web.xml</code>.
 *
 * @param theRequest the incmoing HTTP request
 * @param theResponse the returned HTTP response
 * @param theChain the chain of filters extracted from the definition
 *        given in <code>web.xml</code> by the container.
 */
public void doFilter(ServletRequest theRequest,
    ServletResponse theResponse, FilterChain theChain)
    throws IOException, ServletException
{
    OutputStream out = theResponse.getOutputStream();
    addHeader(out);

    // Create a wrapper of the response so that we can later write to
    // the response (add the footer). If we did not do this, we would
    // get an error saying that the response has already been
    // committed.
    GenericResponseWrapper wrapper =
        new GenericResponseWrapper((HttpServletResponse) theResponse);

    theChain.doFilter(theRequest, wrapper);

    out.write(wrapper.getData());
    addFooter(out);
    out.close();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:SampleFilter.java

示例3: sendStreamToClient

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * Writes the entire stream from the method to the response stream.
 * 
 * @param response
 *            Response to send data to
 * @throws IOException
 *             An IOException is thrown when we are having problems with
 *             reading the streams
 */
protected void sendStreamToClient(ServletResponse response)
        throws IOException {
    InputStream streamFromServer = method.getResponseBodyAsStream();
    OutputStream responseStream = null;

    if (streamFromServer != null) {
        byte[] buffer = new byte[1024];
        int read = streamFromServer.read(buffer);
        while (read > 0) {
            if (responseStream == null) {
                responseStream = response.getOutputStream();
            }
            responseStream.write(buffer, 0, read);
            read = streamFromServer.read(buffer);
        }
        streamFromServer.close();
    }
    // pock: if we dont't have any content set the length to 0 (corrects the
    // 302 Moved Temporarily processing)
    if (responseStream == null) {
        response.setContentLength(0);
    } else {
        responseStream.flush();
        responseStream.close();
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:36,代码来源:ResponseHandlerBase.java

示例4: getOutputStream

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public OutputStream getOutputStream() {
    ServletResponse response = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getServletResponse();
    try {
        return response.getOutputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ServletBlockingHttpExchange.java

示例5: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的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

示例6: downloadAttachment

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
public String downloadAttachment() throws IOException, MessagingException
{
  if (_attachmentToDownload == null)
  {
    _LOG.severe("No attachment available");
    return null;
  }

  _message.getMessage().getFolder().open(Folder.READ_ONLY);

  InputStream in = _attachmentToDownload.getInputStream();

  FacesContext context = FacesContext.getCurrentInstance();
  // Get the ServletResponse;  nothing on ExternalContext is sufficient
  ServletResponse response = (ServletResponse)
    context.getExternalContext().getResponse();
  response.setContentType(_attachmentToDownload.getContentType());

  // If the size of the attachment is known, pass that on.
  int size = _attachmentToDownload.getSize();
  if (size >= 0)
  {
    response.setContentLength(size);
  }

  if (_LOG.isLoggable(Level.INFO))
    _LOG.info("Downloading content+ [size=" + size +",contentType=" +
              _attachmentToDownload.getContentType() + "]");

  if (response instanceof HttpServletResponse)
  {
    String filename = _attachmentToDownload.getFileName();
    if (filename != null)
    {
      ((HttpServletResponse) response).setHeader(
          "Content-disposition",
          "attachment; filename=\"" + filename + "\"");
    }
  }

  // Pass the text along, 128K at a time.
  try
  {
    OutputStream out = response.getOutputStream();
    try
    {
      byte[] buffer = new byte[131072];
      while (true)
      {
        int count = in.read(buffer);
        if (count < 0)
          break;

        out.write(buffer, 0, count);
      }
    }
    // Close up the response
    finally
    {
      // And tell JSF that we handled everything
      context.responseComplete();
      out.close();
    }
  }
  // And make sure the folder got closed
  finally
  {
    _message.getMessage().getFolder().close(false);
  }

  return null;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:73,代码来源:ShowMessageBackingBean.java


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