/**
   * method to stream the byte array to response object
   *
   * @param fileContents
   * @param fileName
   * @param fileContentType
   * @param response
   * @throws Exception
   */
  protected void streamToResponse(
      org.kuali.kra.proposaldevelopment.bo.AttachmentDataSource attachmentDataSource,
      HttpServletResponse response)
      throws Exception {
    byte[] xbts = attachmentDataSource.getContent();
    ByteArrayOutputStream baos = null;
    try {
      baos = new ByteArrayOutputStream(xbts.length);
      baos.write(xbts);

      WebUtils.saveMimeOutputStreamAsFile(
          response,
          attachmentDataSource.getContentType(),
          baos,
          attachmentDataSource.getFileName());

    } finally {
      try {
        if (baos != null) {
          baos.close();
          baos = null;
        }
      } catch (IOException ioEx) {
        LOG.error("Error while downloading attachment");
        throw new RuntimeException("IOException occurred while downloading attachment", ioEx);
      }
    }
  }
Example #2
0
  /**
   * Handy method to stream the byte array to response object
   *
   * @param attachmentDataSource
   * @param response
   * @throws Exception
   */
  public void streamToResponse(
      AttachmentDataSource attachmentDataSource, HttpServletResponse response) throws Exception {
    byte[] xbts = attachmentDataSource.getContent();

    ByteArrayOutputStream baos = null;
    if (xbts != null)
      try {
        baos = new ByteArrayOutputStream(xbts.length);
        baos.write(xbts);

        WebUtils.saveMimeOutputStreamAsFile(
            response,
            attachmentDataSource.getContentType(),
            baos,
            attachmentDataSource.getFileName());
      } finally {
        try {
          if (baos != null) {
            baos.close();
            baos = null;
          }
        } catch (IOException ioEx) {
          LOG.warn(ioEx.getMessage(), ioEx);
        }
      }
  }