/** * 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, ""); }
/** * 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; }