java.lang.Object
org.klomp.snark.web.MimeTypes
Based on MimeTypes from Jetty 6.1.26, heavily simplified and modified to remove all dependencies on Jetty libs.
Supports mime types only, not encodings. Does not support a default "*" mapping.
This is only for local mappings. Caller should use getServletContext().getMimeType() if this returns null.
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty table, pre-loaded with the system MIME map on Unix hosts with at least 100MB of heap; skipped on Windows, macOS and small-heap configurations.Method Summary
Modifier and TypeMethodDescriptionvoidaddMimeMapping(String extension, String type) Add a MIME mapping.getMimeByExtension(String filename) The MIME type by filename extension.voidloadMimeMap(String resourcePath) Load MIME type mappings from a resource file.private static voidloadMimeMap(Map<String, String> map, String resourcePath) Tries both webapp and system class loader, since Jetty blocks its classes from the webapp class loader.private voidLoad mime types from /etc/mime.types.
Field Details
_mimeMap
Constructor Details
MimeTypes
public MimeTypes()Create an empty table, pre-loaded with the system MIME map on Unix hosts with at least 100MB of heap; skipped on Windows, macOS and small-heap configurations.
Method Details
loadMimeMap
Load MIME type mappings from a resource file.- Parameters:
resourcePath- the resource path in the classpath, without ".properties" extension
loadMimeMap
Tries both webapp and system class loader, since Jetty blocks its classes from the webapp class loader.- Parameters:
map- the map filled with lower-case extension to MIME type mappingsresourcePath- the resource path in the classpath, without the ".properties" extension
loadSystemMimeTypes
private void loadSystemMimeTypes()Load mime types from /etc/mime.types. Format: mimetype suffix1 suffix2 ...getMimeByExtension
The MIME type by filename extension.Returns ONLY local mappings. Caller should use getServletContext().getMimeType() if this returns null.
- Parameters:
filename- A file name- Returns:
- MIME type matching the longest dot extension of the file name, or null if not found
addMimeMapping