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


Java ServletResponse.setContentLength方法代码示例

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


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

示例1: showStatus

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * Show the status of the conf and the filter to the user.
 * 
 * @param request
 *            to get status info from
 * @param response
 *            response to show the status on.
 * @throws java.io.IOException
 *             if the output cannot be written
 */
private void showStatus(final HttpServletRequest request, final ServletResponse response) throws IOException {

    log.debug("showing status");

    if (allowConfSwapViaHttp) {
        String newConfPath = request.getParameter("conf");
        if (!StringUtils.isBlank(newConfPath)) {
            confPath = newConfPath;
            loadUrlRewriterLocal();
        }
    }

    Status status = new Status(confLastLoaded, this);
    status.displayStatusInContainer(request);

    response.setContentType("text/html; charset=UTF-8");
    response.setContentLength(status.getBuffer().length());

    final PrintWriter out = response.getWriter();
    out.write(status.getBuffer().toString());
    out.close();

}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:34,代码来源:UrlRewriteFilter.java

示例2: serviceInitRequest

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
private void serviceInitRequest(ServletResponse response, InputStream is) throws IOException
{
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int n;
    while ((n = is.read(buffer)) >= 0)
    {
        outBuffer.write(buffer, 0, n);
    }
    String url = outBuffer.toString(JrpipServiceRegistry.ENCODE_STRING);
    synchronized (this.registeredUrls)
    {
        if (!this.registeredUrls.contains(url))
        {
            JrpipServiceRegistry.getInstance().registerWebAppAtUrl(this.webapp, url);
            this.registeredUrls.add(url);
        }
    }
    int id = CLIENT_ID.incrementAndGet();
    long vmAndClientId = vmId | (long) id;
    String clientCount = String.valueOf(vmAndClientId);
    response.setContentLength(clientCount.length());
    response.getWriter().write(clientCount);
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:25,代码来源:JrpipServlet.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: 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.setContentLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。