public static String convertToMIME(String[] types, String separator) { for (int i = 0; i < types.length; i++) { types[i] = FileTypesHelper.getMIMEType(types[i]); } return String.join(separator, types); }
/** * Gets the mime-type for a file. Currently the returned file type is * resolved by the filename extension only. * * @param file * the file whose mime-type is requested. * @return the files mime-type <code>String</code> */ public static String getMIMEType(File file) { // Checks for nulls if (file == null) { throw new NullPointerException("File can not be null"); } // Directories if (file.isDirectory()) { // Drives if (file.getParentFile() == null) { return "inode/drive"; } else { return "inode/directory"; } } // Return type from extension return getMIMEType(file.getName()); }
protected String getContentType(FileDescriptor fd) { if (StringUtils.isEmpty(fd.getExtension())) { return FileTypesHelper.DEFAULT_MIME_TYPE; } return FileTypesHelper.getMIMEType("." + fd.getExtension().toLowerCase()); }
protected String getContentType(FileDescriptor fd) { if (StringUtils.isEmpty(fd.getExtension())) { return FileTypesHelper.DEFAULT_MIME_TYPE; } return FileTypesHelper.getMIMEType("." + fd.getExtension().toLowerCase()); }
protected String getContentType(FileDescriptor fd) { if (StringUtils.isEmpty(fd.getExtension())) { return FileTypesHelper.DEFAULT_MIME_TYPE; } return FileTypesHelper.getMIMEType("." + fd.getExtension().toLowerCase()); } }
protected MimeBodyPart createAttachmentPart(SendingAttachment attachment) throws MessagingException { DataSource source = new MyByteArrayDataSource(attachment.getContent()); String mimeType = FileTypesHelper.getMIMEType(attachment.getName()); String encodedFileName = encodeAttachmentName(attachment); String contentId = attachment.getContentId(); if (contentId == null) { contentId = encodedFileName; } String disposition = attachment.getDisposition() != null ? attachment.getDisposition() : Part.INLINE; String charset = MimeUtility.mimeCharset(attachment.getEncoding() != null ? attachment.getEncoding() : StandardCharsets.UTF_8.name()); String contentTypeValue = String.format("%s; charset=%s; name=\"%s\"", mimeType, charset, encodedFileName); MimeBodyPart attachmentPart = new MimeBodyPart(); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-ID", "<" + contentId + ">"); attachmentPart.setHeader("Content-Type", contentTypeValue); attachmentPart.setFileName(encodedFileName); attachmentPart.setDisposition(disposition); return attachmentPart; }
resource.setMIMEType(exportFormat.getContentType()); } else { resource.setMIMEType(FileTypesHelper.getMIMEType(resourceName));