Example usage for javax.activation FileDataSource getContentType

List of usage examples for javax.activation FileDataSource getContentType

Introduction

In this page you can find the example usage for javax.activation FileDataSource getContentType.

Prototype

public String getContentType() 

Source Link

Document

This method returns the MIME type of the data in the form of a string.

Usage

From source file:stg.pr.engine.mailer.SmallEmailAttachment.java

/**
 * Constructs an email attachment with the given name and the file.
 * @param name of the file that will get associated with the email.
 * @param file to be attached./*from   ww w.j  av  a2s.com*/
 * @throws IOException
 */
public SmallEmailAttachment(String name, File file) throws IOException {
    super(name, file); //this will throw exception in case the file does not exist 
    if (file.length() > EMailAttachment.SMALL_SIZE.longValue()) {
        throw new IllegalArgumentException("Small email attachments are for file size < "
                + EMailAttachment.SMALL_SIZE.longValue() + " bytes.");
    }
    FileDataSource fds = new FileDataSource(file);
    contentType = fds.getContentType();
    bytes = FileUtils.readFileToByteArray(file);
}