当前位置: 首页>>代码示例>>Java>>正文


Java FileDataSource.setFileTypeMap方法代码示例

本文整理汇总了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;
}
 
开发者ID:jplag,项目名称:jplag,代码行数:28,代码来源:AccessStructure.java

示例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);
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:40,代码来源:cfMAIL.java

示例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" -> "&lt;myId&gt;".
 * 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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:MimeMessageHelper.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MimeMessageHelper.java


注:本文中的javax.activation.FileDataSource.setFileTypeMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。