/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(File file) { return getFileTypeMap().getContentType(file); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(String fileName) { return getFileTypeMap().getContentType(fileName); }
/** * This method returns the MIME type of the data in the form of a * string. This method uses the currently installed FileTypeMap. If * there is no FileTypeMap explictly set, the FileDataSource will * call the <code>getDefaultFileTypeMap</code> method on * FileTypeMap to acquire a default FileTypeMap. <i>Note: By * default, the FileTypeMap used will be a MimetypesFileTypeMap.</i> * * @return the MIME Type * @see javax.activation.FileTypeMap#getDefaultFileTypeMap */ public String getContentType() { // check to see if the type map is null? if (typeMap == null) return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); else return typeMap.getContentType(_file); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(String fileName) { return getFileTypeMap().getContentType(fileName); }
/** * Delegates to the underlying FileTypeMap. * @see #getFileTypeMap() */ @Override public String getContentType(File file) { return getFileTypeMap().getContentType(file); }
/** * Add an inline element to the MimeMessage, taking the content from a * {@code org.springframework.core.io.Resource}. * <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>Note that the InputStream returned by the Resource implementation * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke * {@code getInputStream()} multiple times. * <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 resource the resource to take the content from * @throws MessagingException in case of errors * @see #setText * @see #addInline(String, java.io.File) * @see #addInline(String, javax.activation.DataSource) */ public void addInline(String contentId, Resource resource) throws MessagingException { Assert.notNull(resource, "Resource must not be null"); String contentType = getFileTypeMap().getContentType(resource.getFilename()); addInline(contentId, resource, contentType); }
/** * Add an attachment to the MimeMessage, taking the content from an * {@code org.springframework.core.io.InputStreamResource}. * <p>The content type will be determined by the given filename for * the attachment. Thus, any content source will be fine, including * temporary files with arbitrary filenames. * <p>Note that the InputStream returned by the InputStreamSource * implementation needs to be a <i>fresh one on each call</i>, as * JavaMail will invoke {@code getInputStream()} multiple times. * @param attachmentFilename the name of the attachment as it will * appear in the mail * @param inputStreamSource the resource to take the content from * (all of Spring's Resource implementations can be passed in here) * @throws MessagingException in case of errors * @see #addAttachment(String, java.io.File) * @see #addAttachment(String, javax.activation.DataSource) * @see org.springframework.core.io.Resource */ public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource) throws MessagingException { String contentType = getFileTypeMap().getContentType(attachmentFilename); addAttachment(attachmentFilename, inputStreamSource, contentType); }
/** * Add an inline element to the MimeMessage, taking the content from a * {@code org.springframework.core.io.Resource}. * <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>Note that the InputStream returned by the Resource implementation * needs to be a <i>fresh one on each call</i>, as JavaMail will invoke * {@code getInputStream()} multiple times. * <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 resource the resource to take the content from * @throws MessagingException in case of errors * @see #setText * @see #addInline(String, java.io.File) * @see #addInline(String, javax.activation.DataSource) */ public void addInline(String contentId, Resource resource) throws MessagingException { Assert.notNull(resource, "Resource must not be null"); String contentType = getFileTypeMap().getContentType(resource.getFilename()); addInline(contentId, resource, contentType); }
contentType = fileTypeMap.getContentType(resourceFile);
/** * Add an attachment to the MimeMessage, taking the content from an * {@code org.springframework.core.io.InputStreamResource}. * <p>The content type will be determined by the given filename for * the attachment. Thus, any content source will be fine, including * temporary files with arbitrary filenames. * <p>Note that the InputStream returned by the InputStreamSource * implementation needs to be a <i>fresh one on each call</i>, as * JavaMail will invoke {@code getInputStream()} multiple times. * @param attachmentFilename the name of the attachment as it will * appear in the mail * @param inputStreamSource the resource to take the content from * (all of Spring's Resource implementations can be passed in here) * @throws MessagingException in case of errors * @see #addAttachment(String, java.io.File) * @see #addAttachment(String, javax.activation.DataSource) * @see org.springframework.core.io.Resource */ public void addAttachment(String attachmentFilename, InputStreamSource inputStreamSource) throws MessagingException { String contentType = getFileTypeMap().getContentType(attachmentFilename); addAttachment(attachmentFilename, inputStreamSource, contentType); }
String mimeType = FILE_TYPE_MAP.getContentType(pathInfo); System.out.println(String.format("%s: %s", mimeType, pathInfo));
MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(fileName) : fileInfo.getType();
MimeBodyPart attachementBodyPart = new MimeBodyPart(); URL attachmentUrl = getAttachemntURL(attachment); String contentType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(attachmentUrl.getFile()); attachementBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource( attachmentUrl.openStream(), contentType ) )); String fileName = new File(attachmentUrl.getFile()).getName();
/** * Determines the mimeType from the given file name. * Used to override the body content type and used for all attachments. * @param name the file name or class name. * @return the mime type or null for text/plain. */ private String getContentType(final String name) { assert Thread.holdsLock(this); final String type = contentTypes.getContentType(name); if ("application/octet-stream".equalsIgnoreCase(type)) { return null; //Formatters return strings, default to text/plain. } return type; }
/** * Determines the mimeType from the given file name. * Used to override the body content type and used for all attachments. * @param name the file name or class name. * @return the mime type or null for text/plain. */ private String getContentType(final String name) { assert Thread.holdsLock(this); final String type = contentTypes.getContentType(name); if ("application/octet-stream".equalsIgnoreCase(type)) { return null; //Formatters return strings, default to text/plain. } return type; }
/** * This method returns the MIME type of the data in the form of a * string. This method uses the currently installed FileTypeMap. If * there is no FileTypeMap explictly set, the FileDataSource will * call the <code>getDefaultFileTypeMap</code> method on * FileTypeMap to acquire a default FileTypeMap. <i>Note: By * default, the FileTypeMap used will be a MimetypesFileTypeMap.</i> * * @return the MIME Type * @see javax.activation.FileTypeMap#getDefaultFileTypeMap */ public String getContentType() { // check to see if the type map is null? if (typeMap == null) return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); else return typeMap.getContentType(_file); }
final String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation); final String resourceName = getResourceName(resourceLocation); final InputStream is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName);
String mimeType = URLConnection.guessContentTypeFromName(filePath); if (mimeType == null) { mimeType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(filePath);
public AtomMediaResource(final String name, final long length, final Date lastModified, final InputStream is) throws FileNotFoundException { contentType = map.getContentType(name); contentLength = length; this.lastModified = lastModified; inputStream = is; }
mimeType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(filePath);