|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.common.util.MimeTypeUtil
@Immutable public class MimeTypeUtil
A simple utility that determines an appropriate MIME type by matching the extension of the supplied filename against a set of known file extensions.
This utility class may be instantiated to create a new instance with its own set of mappings. If desired, the default mappings
will be loaded using the current thread's context class loader
, and will be loaded from
the /org/modeshape/mime.types
file located on the classpath. The load(InputStream, Map)
method may be
used to load custom mappings (in the standard format) into a Map
instance, which can then be passed to one of the
constructors.
Field Summary | |
---|---|
static String |
MIME_TYPE_EXTENSIONS_RESOURCE_PATH
The default location of the properties file containing the extension patterns to MIME types. |
Constructor Summary | |
---|---|
MimeTypeUtil()
Create a default instance of the extension-based MIME type detector. |
|
MimeTypeUtil(Map<String,String> extensionsToMimeTypes)
Create an instance of the extension-based MIME type detector by using the supplied mappings. |
|
MimeTypeUtil(Map<String,String> extensionsToMimeTypes,
boolean initWithDefaults)
Create an instance of the extension-based MIME type detector by using the supplied mappings. |
Method Summary | |
---|---|
protected static Map<String,String> |
getDefaultMappings()
Load the default extensions from MIME_TYPE_EXTENSIONS_RESOURCE_PATH , which can either be a property file or a
tab-delimited *nix-style MIME types file (common in web servers and libraries). |
static Map<String,String> |
load(InputStream stream,
Map<String,Set<String>> duplicateMimeTypesByExtension)
Load the extensions from the supplied stream, which may provide the contents in the format of property file or a tab-delimited *nix-style MIME types file (common in web servers and libraries). |
String |
mimeTypeOf(File file)
Returns the MIME-type of the file using its name. |
String |
mimeTypeOf(String filename)
Returns the MIME-type of a file given the supplied name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String MIME_TYPE_EXTENSIONS_RESOURCE_PATH
Constructor Detail |
---|
public MimeTypeUtil()
public MimeTypeUtil(Map<String,String> extensionsToMimeTypes)
extensionsToMimeTypes
- the mapping of extension patterns to MIME types, which will override the default mappings; may
be null if the default mappings are to be usedpublic MimeTypeUtil(Map<String,String> extensionsToMimeTypes, boolean initWithDefaults)
extensionsToMimeTypes
- the mapping of extension patterns to MIME types, which will override the default mappings; may
be null if the default mappings are to be usedinitWithDefaults
- true if the default mappings are to be loaded first, or false if the default mappings are not to be
used at allMethod Detail |
---|
protected static Map<String,String> getDefaultMappings()
MIME_TYPE_EXTENSIONS_RESOURCE_PATH
, which can either be a property file or a
tab-delimited *nix-style MIME types file (common in web servers and libraries). If an extension applies to more than one
MIME type, the first one in the file wins.
public static Map<String,String> load(InputStream stream, Map<String,Set<String>> duplicateMimeTypesByExtension)
stream
- the stream containing the content; may not be nullduplicateMimeTypesByExtension
- a map into which any extension should be placed if there are multiple MIME types that
apply; may be null if this information is not required
public String mimeTypeOf(String filename)
null
is
returned.
filename
- the file name; may be null
.
null
if the MIME-type could not be determined.public String mimeTypeOf(File file)
null
is returned.
file
- the file; may be null
.
null
if the MIME-type could not be determined.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |