本文整理汇总了Java中javax.activation.FileDataSource.setFileTypeMap方法的典型用法代码示例。如果您正苦于以下问题:Java FileDataSource.setFileTypeMap方法的具体用法?Java FileDataSource.setFileTypeMap怎么用?Java FileDataSource.setFileTypeMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.activation.FileDataSource
的用法示例。
在下文中一共展示了FileDataSource.setFileTypeMap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResult
import javax.activation.FileDataSource; //导入方法依赖的package包/类
/**
* @return A MimeMultipart object containing the zipped result files
*/
public MimeMultipart getResult() {
File file = new File(JPLAG_RESULTS_DIRECTORY + File.separator
+ submissionID + getUsername() + ".zip");
MimeMultipart mmp = new MimeMultipart();
FileDataSource fds1 = new FileDataSource(file);
MimetypesFileTypeMap mftp = new MimetypesFileTypeMap();
mftp.addMimeTypes("multipart/zip zip ZIP");
fds1.setFileTypeMap(mftp);
MimeBodyPart mbp = new MimeBodyPart();
try {
mbp.setDataHandler(new DataHandler(fds1));
mbp.setFileName(file.getName());
mmp.addBodyPart(mbp);
} catch (MessagingException me) {
me.printStackTrace();
}
return mmp;
}
示例2: addAttachments
import javax.activation.FileDataSource; //导入方法依赖的package包/类
private void addAttachments( Enumeration<fileAttachment> _attach, Multipart _parent, boolean _isInline ) throws MessagingException{
while ( _attach.hasMoreElements() ){
fileAttachment nextFile = _attach.nextElement();
FileDataSource fds = new FileDataSource( nextFile.getFilepath() );
String mimeType = nextFile.getMimetype();
if (mimeType == null){
// if mime type not supplied then auto detect
mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(nextFile.getFilepath());
}else{
// since mime type is not null then it the mime type has been set manually therefore
// we need to ensure that any call to the underlying FileDataSource.getFileTypeMap()
// returns a FileTypeMap that will map to this type
fds.setFileTypeMap(new CustomFileTypeMap(mimeType));
}
String filename = cleanName(fds.getName());
try {
// encode the filename to ensure that it contains US-ASCII characters only
filename = MimeUtility.encodeText( filename, "utf-8", "b" );
} catch (UnsupportedEncodingException e5) {
// shouldn't occur
}
MimeBodyPart mimeAttach = new MimeBodyPart();
mimeAttach.setDataHandler( new DataHandler(fds) );
mimeAttach.setFileName( filename );
ContentType ct = new ContentType(mimeType);
ct.setParameter("name", filename );
mimeAttach.setHeader("Content-Type", ct.toString() );
if ( _isInline ){
mimeAttach.setDisposition( "inline" );
mimeAttach.addHeader( "Content-id", "<" + nextFile.getContentid() + ">" );
}
_parent.addBodyPart(mimeAttach);
}
}
示例3: addInline
import javax.activation.FileDataSource; //导入方法依赖的package包/类
/**
* Add an inline element to the MimeMessage, taking the content from a
* {@code java.io.File}.
* <p>The content type will be determined by the name of the given
* content file. Do not use this for temporary files with arbitrary
* filenames (possibly ending in ".tmp" or the like)!
* <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
* else, mail readers might not be able to resolve inline references correctly.
* @param contentId the content ID to use. Will end up as "Content-ID" header
* in the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".
* Can be referenced in HTML source via src="cid:myId" expressions.
* @param file the File resource to take the content from
* @throws MessagingException in case of errors
* @see #setText
* @see #addInline(String, org.springframework.core.io.Resource)
* @see #addInline(String, javax.activation.DataSource)
*/
public void addInline(String contentId, File file) throws MessagingException {
Assert.notNull(file, "File must not be null");
FileDataSource dataSource = new FileDataSource(file);
dataSource.setFileTypeMap(getFileTypeMap());
addInline(contentId, dataSource);
}
示例4: addAttachment
import javax.activation.FileDataSource; //导入方法依赖的package包/类
/**
* Add an attachment to the MimeMessage, taking the content from a
* {@code java.io.File}.
* <p>The content type will be determined by the name of the given
* content file. Do not use this for temporary files with arbitrary
* filenames (possibly ending in ".tmp" or the like)!
* @param attachmentFilename the name of the attachment as it will
* appear in the mail
* @param file the File resource to take the content from
* @throws MessagingException in case of errors
* @see #addAttachment(String, org.springframework.core.io.InputStreamSource)
* @see #addAttachment(String, javax.activation.DataSource)
*/
public void addAttachment(String attachmentFilename, File file) throws MessagingException {
Assert.notNull(file, "File must not be null");
FileDataSource dataSource = new FileDataSource(file);
dataSource.setFileTypeMap(getFileTypeMap());
addAttachment(attachmentFilename, dataSource);
}