/** * return the content-type from a file name. If none is found returning * application/octet-stream<br/> * For a text-based content-type, also return the encoding suffix eg. * <em>"text/plain; charset=utf-8"</em> * * @param filename * the file name * @return the content-type deduced from the file extension. */ public String getContentType(Context context, String filename) { return getContentType(context, filename, "application/octet-stream"); }
/** * return the mimetype from a file name * * @param filename * the file name * @return the mimetype or the empty string if not found */ public String getMimeType(String filename) { return getMimeType(filename, ""); }
@Inject public MimeTypes(NinjaProperties ninjaProperties) { this.ninjaProperties = ninjaProperties; this.extPattern = Pattern.compile("^.*\\.([^.]+)$"); mimetypes = new Properties(); initMimetypes(); }
/** * return the content-type from a file name.<br/> * For a text-based content-type, also return the encoding suffix eg. * <em>"text/plain; charset=utf-8"</em> * * @param filename * the file name * @param defaultContentType * the default content-type to return when no matching * content-type is found * @return the content-type deduced from the file extension. */ public String getContentType(Context context, String filename, String defaultContentType) { String contentType = getMimeType(filename, null); if (contentType == null) { contentType = defaultContentType; } if (contentType != null && contentType.startsWith("text/")) { // UTF-8 is fixed for now as ninja only supports utf-8 in files... return contentType + "; charset=utf-8"; } return contentType; }
String mimeType = mimeTypes.getContentType(context, url.getFile());