@Override public String apply(MimeType mimeType) { return mimeType.toString(); } };
/** Two mime types are considered equal if type and subtype are equal. */ public boolean eq(MimeType other) { return eq(other.getType(), other.getSubtype()); }
public static MimeType mimeType(String type, String subtype, List<String> suffixes, List<MimeType> equivalents, Option<String> description, Option<String> flavor, Option<String> flavorDescription) { return new MimeType(type, subtype, suffixes, equivalents, description, flavor, flavorDescription); }
/** * Returns a mime type for the given type and subtype, e. g. <code>video/mj2</code>. * * @param mimeType * the mime type * @return the corresponding mime type */ public static MimeType parseMimeType(String mimeType) { final Matcher m = MIME_TYPE_PATTERN.matcher(mimeType); if (!m.matches()) throw new IllegalArgumentException("Malformed mime type '" + mimeType + "'"); final String type = m.group(1); final String subtype = m.group(2); for (MimeType t : mimeTypes) { if (t.getType().equals(type) && t.getSubtype().equals(subtype)) return t; } return mimeType(type, subtype); }
/** Get a mime type from the registry. */ public static Option<MimeType> get(String type, String subtype) { for (MimeType t : mimeTypes) { if (t.getType().equals(type) && t.getSubtype().equals(subtype)) return some(t); } return none(); }
@Override public Boolean apply(MimeType other) { return eq(other); } };
if (mimeTypes.length > 0) { for (MimeType m : mimeTypes) { if (m.equals(MimeTypes.fromURL(file.toURI().toURL()))) return true;
@Override public boolean equals(Object that) { return (this == that) || (that instanceof MimeType && eqFields((MimeType) that)); }
if ("audio".equals(mimeType.getType()) && metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("video/" + mimeType.getSubtype()); } else if ("video".equals(mimeType.getType()) && !metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("audio/" + mimeType.getSubtype());
/** * Returns <code>true</code> if this mime type is an equivalent for the specified type and subtype. * <p> * For example, a gzipped file may have both of these mime types defined, <code>application/x-compressed</code> or * <code>application/x-gzip</code>. * * @return <code>true</code> if this mime type is equal */ public boolean isEquivalentTo(String type, String subtype) { return eq(type, subtype) || mlist(equivalents).exists(eq); }
if (mimeTypes.size() > 0) { for (MimeType m : mimeTypes) { if (m.equals(MimeTypes.fromURL(file.toURI().toURL()))) return true;
@Override public String apply(MimeType mimeType) { return mimeType.toString(); } };
if ("audio".equals(mimeType.getType()) && metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("video/" + mimeType.getSubtype()); } else if ("video".equals(mimeType.getType()) && !metadata.hasVideoStreamMetadata()) { mimeType = MimeTypes.parseMimeType("audio/" + mimeType.getSubtype());
public static MimeType mimeType(String type, String subtype) { return new MimeType(type, subtype, Collections.<String>nil(), Collections.<MimeType>nil(), none(""), none(""), none("")); }
/** * Returns the MimeType as a string of the form <code>type/subtype</code> * @deprecated use {@link #toString()} instead */ public String asString() { return toString(); }
public static MimeType mimeType(String type, String subtype, String suffix) { return new MimeType(type, subtype, list(suffix), Collections.<MimeType>nil(), none(""), none(""), none("")); }
/** * {@inheritDoc} * * @see org.osgi.service.http.HttpContext#getMimeType(java.lang.String) */ @Override public String getMimeType(String name) { try { return MimeTypes.fromString(name).toString(); } catch (UnknownFileTypeException e) { return null; } }
/** * Convenience method to get a mime type as String from a filename extension * * @param name * the filename * @return the corresponding mime type or DEFAULT_TYPE if no match */ public static String getMimeType(String name) { try { return MimeTypes.fromString(name).toString(); } catch (UnknownFileTypeException e) { return DEFAULT_TYPE; } }
private Option<String> getMimeType(final String filename) { Option<String> mimeType; try { mimeType = Option.some(MimeTypes.fromString(filename).toString()); } catch (Exception e) { logger.warn("Unable to detect the mime type of file {}", filename); mimeType = Option.<String> none(); } return mimeType; }