本文整理汇总了Java中javax.activation.FileTypeMap类的典型用法代码示例。如果您正苦于以下问题:Java FileTypeMap类的具体用法?Java FileTypeMap怎么用?Java FileTypeMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTypeMap类属于javax.activation包,在下文中一共展示了FileTypeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentType
import javax.activation.FileTypeMap; //导入依赖的package包/类
/**
* Get the Content type for this file
*
* @return Http Response content type
*/
public String getContentType() {
String contentType;
if (outputFormat != null) {
contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(fullName + "." + outputFormat);
} else {
contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(fullName);
}
if (contentType != null && contentType.startsWith("text")) {
contentType += ";charset=" + CHARSET;
}
return (contentType != null) ? contentType : "application/octet-stream";
}
示例2: javaMailSenderWithMimeMessageHelperAndSpecificEncoding
import javax.activation.FileTypeMap; //导入依赖的package包/类
@Test
public void javaMailSenderWithMimeMessageHelperAndSpecificEncoding() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), "UTF-8");
assertEquals("UTF-8", message.getEncoding());
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
message.setFileTypeMap(fileTypeMap);
assertEquals(fileTypeMap, message.getFileTypeMap());
message.setTo("[email protected]");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
}
示例3: javaMailSenderWithMimeMessageHelperAndDefaultEncoding
import javax.activation.FileTypeMap; //导入依赖的package包/类
@Test
public void javaMailSenderWithMimeMessageHelperAndDefaultEncoding() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
sender.setDefaultEncoding("UTF-8");
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
sender.setDefaultFileTypeMap(fileTypeMap);
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
assertEquals("UTF-8", message.getEncoding());
assertEquals(fileTypeMap, message.getFileTypeMap());
message.setTo("[email protected]");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
}
示例4: getActivityLogFile
import javax.activation.FileTypeMap; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public Optional<VFile> getActivityLogFile(final Long actityExecutionId) {
Assertion.checkNotNull(actityExecutionId);
// ---
final Optional<OActivityLog> activityLog = activityLogDAO.getActivityLogByAceId(actityExecutionId);
if (activityLog.isPresent()) {
final byte[] stringByteArray = activityLog.get().getLog().getBytes(StandardCharsets.UTF_8);
final InputStreamBuilder inputStreamBuilder = () -> new ByteArrayInputStream(stringByteArray);
final String fileName = TECHNICAL_LOG_PREFIX + actityExecutionId + TECHNICAL_LOG_EXTENSION;
final VFile file = fileManager.createFile(fileName, FileTypeMap.getDefaultFileTypeMap().getContentType(fileName), new Date(), stringByteArray.length, inputStreamBuilder);
return Optional.<VFile> of(file);
}
return Optional.<VFile> empty();
}
示例5: getContentType
import javax.activation.FileTypeMap; //导入依赖的package包/类
@Override
public ContentType getContentType(final String contentName)
{
ContentType ret = null;
final int idx = contentName.lastIndexOf('.');
if (idx >= 0)
{
final String ext = contentName.substring(idx); // Shall not throw IndexOutOfBoundsException.
final FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
final String contentType = map.getContentType(contentName);
// Test the default map.
if (!"application/octet-stream".equals(contentType))
{
ret = new ContentType(new String[] { ext }, new String[] { contentType }, null, null);
}
}
return ret;
}
示例6: testJavaMailSenderWithMimeMessageHelperAndSpecificEncoding
import javax.activation.FileTypeMap; //导入依赖的package包/类
public void testJavaMailSenderWithMimeMessageHelperAndSpecificEncoding() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), "UTF-8");
assertEquals("UTF-8", message.getEncoding());
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
message.setFileTypeMap(fileTypeMap);
assertEquals(fileTypeMap, message.getFileTypeMap());
message.setTo("[email protected]");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
}
示例7: testJavaMailSenderWithMimeMessageHelperAndDefaultEncoding
import javax.activation.FileTypeMap; //导入依赖的package包/类
public void testJavaMailSenderWithMimeMessageHelperAndDefaultEncoding() throws MessagingException {
MockJavaMailSender sender = new MockJavaMailSender();
sender.setHost("host");
sender.setUsername("username");
sender.setPassword("password");
sender.setDefaultEncoding("UTF-8");
FileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
sender.setDefaultFileTypeMap(fileTypeMap);
MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
assertEquals("UTF-8", message.getEncoding());
assertEquals(fileTypeMap, message.getFileTypeMap());
message.setTo("[email protected]");
sender.send(message.getMimeMessage());
assertEquals("host", sender.transport.getConnectedHost());
assertEquals("username", sender.transport.getConnectedUsername());
assertEquals("password", sender.transport.getConnectedPassword());
assertTrue(sender.transport.isCloseCalled());
assertEquals(1, sender.transport.getSentMessages().size());
assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
}
示例8: getContentType
import javax.activation.FileTypeMap; //导入依赖的package包/类
@Override
public String getContentType(File filename) {
if (!filename.exists()) {
return null;
}
try {
final MimeType type = getMimeType(filename.toURI().toURL());
if (type != null) {
return type.toString();
}
} catch (Exception e) {
//
}
final FileTypeMap lparent = this.parent.get();
if (lparent != null) {
return lparent.getContentType(filename);
}
return MimeName.MIME_OCTET_STREAM.getMimeConstant();
}
示例9: getFileTypeMap
import javax.activation.FileTypeMap; //导入依赖的package包/类
/**
* Return the delegate FileTypeMap, compiled from the mappings in the mapping file
* and the entries in the {@code mappings} property.
* @see #setMappingLocation
* @see #setMappings
* @see #createFileTypeMap
*/
protected final FileTypeMap getFileTypeMap() {
if (this.fileTypeMap == null) {
try {
this.fileTypeMap = createFileTypeMap(this.mappingLocation, this.mappings);
}
catch (IOException ex) {
throw new IllegalStateException(
"Could not load specified MIME type mapping file: " + this.mappingLocation, ex);
}
}
return this.fileTypeMap;
}
示例10: initFileTypeMap
import javax.activation.FileTypeMap; //导入依赖的package包/类
private static void initFileTypeMap() {
fileTypeMap = new MimetypesFileTypeMap();
// Additional MIME types
fileTypeMap.addMimeTypes("application/atom+xml atom");
fileTypeMap.addMimeTypes("application/msword doc dot");
fileTypeMap.addMimeTypes("application/mspowerpoint ppt pot");
fileTypeMap.addMimeTypes("application/msexcel xls");
fileTypeMap.addMimeTypes("application/pdf pdf");
fileTypeMap.addMimeTypes("application/rdf+xml rdf rss");
fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat docx docm dotx dotm");
fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat xlsx xlsm");
fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat pptx pptm potx");
fileTypeMap.addMimeTypes("application/x-javascript js");
fileTypeMap.addMimeTypes("application/x-rar-compressed rar");
fileTypeMap.addMimeTypes("application/x-textedit bat cmd");
fileTypeMap.addMimeTypes("application/zip zip");
fileTypeMap.addMimeTypes("audio/mpeg mp3");
fileTypeMap.addMimeTypes("image/bmp bmp");
fileTypeMap.addMimeTypes("image/gif gif");
fileTypeMap.addMimeTypes("image/jpeg jpg jpeg jpe");
fileTypeMap.addMimeTypes("image/png png");
fileTypeMap.addMimeTypes("text/css css");
fileTypeMap.addMimeTypes("text/csv csv");
fileTypeMap.addMimeTypes("text/html htm html");
fileTypeMap.addMimeTypes("text/xml xml");
fileTypeMap.addMimeTypes("video/quicktime qt mov moov");
fileTypeMap.addMimeTypes("video/mpeg mpeg mpg mpe mpv vbs mpegv");
fileTypeMap.addMimeTypes("video/msvideo avi");
fileTypeMap.addMimeTypes("video/mp4 mp4");
fileTypeMap.addMimeTypes("video/ogg ogg");
FileTypeMap.setDefaultFileTypeMap(fileTypeMap);
}
示例11: getMimeTypeWithCustomConfiguredType
import javax.activation.FileTypeMap; //导入依赖的package包/类
/**
* Introduced to dispel claims in a thread on Stack Overflow:
* <a href="http://stackoverflow.com/questions/22986109/testing-spring-managed-servlet">Testing Spring managed servlet</a>
*/
@Test
public void getMimeTypeWithCustomConfiguredType() {
FileTypeMap defaultFileTypeMap = FileTypeMap.getDefaultFileTypeMap();
assertThat(defaultFileTypeMap, instanceOf(MimetypesFileTypeMap.class));
MimetypesFileTypeMap mimetypesFileTypeMap = (MimetypesFileTypeMap) defaultFileTypeMap;
mimetypesFileTypeMap.addMimeTypes("text/enigma enigma");
assertEquals("text/enigma", sc.getMimeType("filename.enigma"));
}
示例12: getContentType
import javax.activation.FileTypeMap; //导入依赖的package包/类
public String getContentType() {
if (typeMap == null) {
return FileTypeMap.getDefaultFileTypeMap().getContentType(fileName);
} else {
return typeMap.getContentType(fileName);
}
}
示例13: getFileTypeMap
import javax.activation.FileTypeMap; //导入依赖的package包/类
public FileTypeMap getFileTypeMap() {
if (fileTypeMap == null) {
fileTypeMap = loadFileTypeMapFromContextSupportModule();
}
return fileTypeMap;
}
示例14: SmartMimeMessage
import javax.activation.FileTypeMap; //导入依赖的package包/类
/**
* Create a new SmartMimeMessage.
* @param session the JavaMail Session to create the message for
* @param defaultEncoding the default encoding, or {@code null} if none
* @param defaultFileTypeMap the default FileTypeMap, or {@code null} if none
*/
public SmartMimeMessage(final Session session,
final String defaultEncoding,
final FileTypeMap defaultFileTypeMap) {
super(session);
_defaultEncoding = defaultEncoding;
_defaultFileTypeMap = defaultFileTypeMap;
}
示例15: getContentType
import javax.activation.FileTypeMap; //导入依赖的package包/类
public static String getContentType(String filename){
if(filetypeMap == null) {
filetypeMap = FileTypeMap.getDefaultFileTypeMap();
}
return filetypeMap.getContentType(filename);
}