コード例 #1
0
  private FetchAttachmentResult fetchAttachment(BackendSession bs, String reference)
      throws CollectionNotFoundException, DaoException, ProcessingEmailException {

    FetchAttachmentResult fetchResult = new FetchAttachmentResult();
    try {
      MSAttachementData data = contentsExporter.getEmailAttachement(bs, reference);
      fetchResult.setContentType(data.getContentType());
      try {
        fetchResult.setAttch(FileUtils.streamBytes(data.getFile(), true));
        fetchResult.setStatus(ItemOperationsStatus.SUCCESS);
      } catch (Throwable e) {
        fetchResult.setStatus(ItemOperationsStatus.MAILBOX_ITEM_FAILED_CONVERSATION);
      }
    } catch (AttachementNotFoundException e) {
      fetchResult.setStatus(ItemOperationsStatus.MAILBOX_INVALID_ATTACHMENT_ID);
    }

    return fetchResult;
  }
コード例 #2
0
  /**
   * Returns a string representation of the given value.
   *
   * @param val the value to represent as a string
   * @return a string representation of the given value
   * @throws IOException if an error occurs while processing value
   */
  private static String toString(Object val) throws IOException {
    String v = null;
    if (val != null) {
      if (val instanceof Date) {
        // format the date according to given format string
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        return df.format((Date) val);
      } else if (val instanceof RawInputStream) {
        RawInputStream ris = (RawInputStream) val;
        if (ris != null) {
          byte[] b = FileUtils.streamBytes(ris, false);

          return new String(b, Charset.forName("US-ASCII"));
        }
      } else {
        v = val.toString();
      }
    }
    return v;
  }