microsoft.exchange.webservices.data.property.complex.FileAttachment Java Examples

The following examples show how to use microsoft.exchange.webservices.data.property.complex.FileAttachment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Contact.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Retrieves the file attachment that holds the contact's picture.
 *
 * @return The file attachment that holds the contact's picture.
 * @throws ServiceLocalException the service local exception
 */
public FileAttachment getContactPictureAttachment()
    throws ServiceLocalException {
  EwsUtilities.validateMethodVersion(this.getService(),
      ExchangeVersion.Exchange2010, "GetContactPictureAttachment");

  if (!this.getPropertyBag().isPropertyLoaded(ContactSchema.Attachments)) {
    throw new PropertyException("The attachment collection must be loaded.");
  }

  for (Attachment fileAttachment : this.getAttachments()) {
    if (fileAttachment instanceof FileAttachment) {
      if (((FileAttachment) fileAttachment).isContactPhoto()) {
        return (FileAttachment) fileAttachment;
      }
    }
  }
  return null;
}
 
Example #2
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream readAttachment(Attachment a) throws FileSystemException, IOException {
	try {
		a.load();
	} catch (Exception e) {
		throw new FileSystemException("Cannot load attachment",e);
	}
	byte[] content = null;
	if (a instanceof FileAttachment) {
		content=((FileAttachment)a).getContent(); // TODO: should do streaming, instead of via byte array
	}
	if (a instanceof ItemAttachment) {
		ItemAttachment itemAttachment=(ItemAttachment)a;
		Item attachmentItem = itemAttachment.getItem();
		return readFile(attachmentItem);
	}
	if (content==null) {
		log.warn("content of attachment is null");
		content = new byte[0];
	}
	InputStream binaryInputStream = new ByteArrayInputStream(content);
	return binaryInputStream;
}
 
Example #3
Source File: Contact.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Sets the contact's picture using the specified byte array.
 *
 * @param content the new contact picture
 * @throws Exception the exception
 */
public void setContactPicture(byte[] content) throws Exception {
  EwsUtilities.validateMethodVersion(this.getService(), ExchangeVersion.Exchange2010, "SetContactPicture");

  internalRemoveContactPicture();
  FileAttachment fileAttachment = getAttachments().addFileAttachment(
      ContactPictureName, content);
  fileAttachment.setIsContactPhoto(true);
}
 
Example #4
Source File: Contact.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Sets the contact's picture using the specified stream.
 *
 * @param contentStream the new contact picture
 * @throws Exception the exception
 */
public void setContactPicture(InputStream contentStream) throws Exception {
  EwsUtilities.validateMethodVersion(this.getService(),
      ExchangeVersion.Exchange2010, "SetContactPicture");

  internalRemoveContactPicture();
  FileAttachment fileAttachment = getAttachments().addFileAttachment(
      ContactPictureName, contentStream);
  fileAttachment.setIsContactPhoto(true);
}
 
Example #5
Source File: Contact.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Sets the contact's picture using the specified file.
 *
 * @param fileName the new contact picture
 * @throws Exception the exception
 */
public void setContactPicture(String fileName) throws Exception {
  EwsUtilities.validateMethodVersion(this.getService(),
      ExchangeVersion.Exchange2010, "SetContactPicture");

  internalRemoveContactPicture();
  FileAttachment fileAttachment = getAttachments().addFileAttachment(
      new File(fileName).getName(), fileName);
  fileAttachment.setIsContactPhoto(true);
}
 
Example #6
Source File: Contact.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Removes the picture from local attachment collection.
 *
 * @throws Exception the exception
 */
private void internalRemoveContactPicture() throws Exception {
  // Iterates in reverse order to remove file attachments that have
  // IsContactPhoto set to true.
  for (int index = this.getAttachments().getCount() - 1; index >= 0; index--) {
    FileAttachment fileAttachment = (FileAttachment) this
        .getAttachments().getPropertyAtIndex(index);
    if (fileAttachment != null) {
      if (fileAttachment.isContactPhoto()) {
        this.getAttachments().remove(fileAttachment);
      }
    }
  }

}
 
Example #7
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public String getAttachmentFileName(Attachment a) throws FileSystemException {
	if (a instanceof FileAttachment) {
		return ((FileAttachment)a).getFileName();
	}
	return null;
}