Skip to content

MIME Type Reference — Java source

A searchable map of common file extensions to their MIME types - text, image, audio, video, application, font, and multipart. Look up by extension or by type, filter by category, and copy the exact Content-Type string for any format.

This is the Java implementation — the same logic the interactive tool runs, in a shareable, citable form.

// mime-types — Java 17 port of the curated extension ↔ MIME table, ported
// from src/lib/mime-types.ts. Display source for CosmoDev's polyglot tool
// pages.
//
// The table is an immutable List of 71 entries grouped by the seven top-level
// media types (RFC 2046). Each entry's type always equals the top-level
// segment of its own mime, so the category filter and the Content-Type never
// disagree.

import java.util.List;
import java.util.Locale;

public final class MimeTypes {

    /** The seven top-level media types a curated entry can belong to. */
    public enum Category { TEXT, IMAGE, AUDIO, VIDEO, APPLICATION, FONT, MULTIPART }

    /** One curated extension ↔ MIME mapping (immutable value object). */
    public record MimeEntry(
            String ext,   // lowercase, no leading dot (e.g. "json")
            String mime,  // full Content-Type (e.g. "application/json")
            Category type, // always the top-level segment of `mime`
            String name   // human-readable format name (e.g. "JSON")
    ) {}

    /** Display order of the categories (used by the UI filter). */
    public static final List<Category> MIME_CATEGORIES = List.of(Category.values());

    /**
     * The curated extension ↔ MIME table. One entry is one (extension, type)
     * pair, so an extension with several MIME types (e.g. .js) appears more
     * than once, and a MIME with several extensions (e.g. image/jpeg)
     * appears once per extension. Values follow IANA / MDN conventions.
     */
    private static final List<MimeEntry> MIME = List.of(
            // ── text ────────────────────────────────────────────────────
            new MimeEntry("txt", "text/plain", Category.TEXT, "Plain text"),
            new MimeEntry("html", "text/html", Category.TEXT, "HTML document"),
            new MimeEntry("htm", "text/html", Category.TEXT, "HTML document"),
            new MimeEntry("xhtml", "application/xhtml+xml", Category.APPLICATION, "XHTML"),
            new MimeEntry("css", "text/css", Category.TEXT, "CSS stylesheet"),
            new MimeEntry("csv", "text/csv", Category.TEXT, "Comma-separated values"),
            new MimeEntry("xml", "application/xml", Category.APPLICATION, "XML document"),
            new MimeEntry("js", "text/javascript", Category.TEXT, "JavaScript"),
            new MimeEntry("js", "application/javascript", Category.APPLICATION, "JavaScript (legacy)"),
            new MimeEntry("mjs", "text/javascript", Category.TEXT, "JavaScript module"),
            new MimeEntry("json", "application/json", Category.APPLICATION, "JSON"),
            new MimeEntry("md", "text/markdown", Category.TEXT, "Markdown"),
            new MimeEntry("yaml", "text/yaml", Category.TEXT, "YAML"),
            new MimeEntry("yml", "text/yaml", Category.TEXT, "YAML"),
            new MimeEntry("ics", "text/calendar", Category.TEXT, "iCalendar"),
            new MimeEntry("rtf", "application/rtf", Category.APPLICATION, "Rich text"),
            new MimeEntry("tsv", "text/tab-separated-values", Category.TEXT, "Tab-separated values"),

            // ── image ───────────────────────────────────────────────────
            new MimeEntry("jpg", "image/jpeg", Category.IMAGE, "JPEG image"),
            new MimeEntry("jpeg", "image/jpeg", Category.IMAGE, "JPEG image"),
            new MimeEntry("png", "image/png", Category.IMAGE, "PNG image"),
            new MimeEntry("gif", "image/gif", Category.IMAGE, "GIF image"),
            new MimeEntry("webp", "image/webp", Category.IMAGE, "WebP image"),
            new MimeEntry("avif", "image/avif", Category.IMAGE, "AVIF image"),
            new MimeEntry("svg", "image/svg+xml", Category.IMAGE, "SVG image"),
            new MimeEntry("bmp", "image/bmp", Category.IMAGE, "Bitmap image"),
            new MimeEntry("ico", "image/x-icon", Category.IMAGE, "Icon"),
            new MimeEntry("tif", "image/tiff", Category.IMAGE, "TIFF image"),
            new MimeEntry("tiff", "image/tiff", Category.IMAGE, "TIFF image"),
            new MimeEntry("heic", "image/heic", Category.IMAGE, "HEIC image"),

            // ── audio ───────────────────────────────────────────────────
            new MimeEntry("mp3", "audio/mpeg", Category.AUDIO, "MP3 audio"),
            new MimeEntry("wav", "audio/wav", Category.AUDIO, "WAV audio"),
            new MimeEntry("ogg", "audio/ogg", Category.AUDIO, "Ogg audio"),
            new MimeEntry("oga", "audio/ogg", Category.AUDIO, "Ogg audio"),
            new MimeEntry("flac", "audio/flac", Category.AUDIO, "FLAC audio"),
            new MimeEntry("aac", "audio/aac", Category.AUDIO, "AAC audio"),
            new MimeEntry("m4a", "audio/mp4", Category.AUDIO, "M4A audio"),
            new MimeEntry("weba", "audio/webm", Category.AUDIO, "WebM audio"),
            new MimeEntry("mid", "audio/midi", Category.AUDIO, "MIDI"),
            new MimeEntry("midi", "audio/midi", Category.AUDIO, "MIDI"),

            // ── video ───────────────────────────────────────────────────
            new MimeEntry("mp4", "video/mp4", Category.VIDEO, "MP4 video"),
            new MimeEntry("webm", "video/webm", Category.VIDEO, "WebM video"),
            new MimeEntry("avi", "video/x-msvideo", Category.VIDEO, "AVI video"),
            new MimeEntry("mov", "video/quicktime", Category.VIDEO, "QuickTime video"),
            new MimeEntry("mkv", "video/x-matroska", Category.VIDEO, "Matroska video"),
            new MimeEntry("mpeg", "video/mpeg", Category.VIDEO, "MPEG video"),
            new MimeEntry("mpg", "video/mpeg", Category.VIDEO, "MPEG video"),
            new MimeEntry("ogv", "video/ogg", Category.VIDEO, "Ogg video"),
            new MimeEntry("m4v", "video/mp4", Category.VIDEO, "M4V video"),

            // ── application ─────────────────────────────────────────────
            new MimeEntry("pdf", "application/pdf", Category.APPLICATION, "PDF document"),
            new MimeEntry("zip", "application/zip", Category.APPLICATION, "ZIP archive"),
            new MimeEntry("gz", "application/gzip", Category.APPLICATION, "Gzip archive"),
            new MimeEntry("tar", "application/x-tar", Category.APPLICATION, "Tar archive"),
            new MimeEntry("rar", "application/vnd.rar", Category.APPLICATION, "RAR archive"),
            new MimeEntry("7z", "application/x-7z-compressed", Category.APPLICATION, "7-Zip archive"),
            new MimeEntry("bin", "application/octet-stream", Category.APPLICATION, "Binary data"),
            new MimeEntry("exe", "application/x-msdownload", Category.APPLICATION, "Windows executable"),
            new MimeEntry("jar", "application/java-archive", Category.APPLICATION, "Java archive"),
            new MimeEntry("wasm", "application/wasm", Category.APPLICATION, "WebAssembly"),
            new MimeEntry("doc", "application/msword", Category.APPLICATION, "Word document"),
            new MimeEntry("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Category.APPLICATION, "Word document (OOXML)"),
            new MimeEntry("xls", "application/vnd.ms-excel", Category.APPLICATION, "Excel spreadsheet"),
            new MimeEntry("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Category.APPLICATION, "Excel spreadsheet (OOXML)"),
            new MimeEntry("ppt", "application/vnd.ms-powerpoint", Category.APPLICATION, "PowerPoint"),
            new MimeEntry("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", Category.APPLICATION, "PowerPoint (OOXML)"),

            // ── font ────────────────────────────────────────────────────
            new MimeEntry("woff", "font/woff", Category.FONT, "WOFF font"),
            new MimeEntry("woff2", "font/woff2", Category.FONT, "WOFF2 font"),
            new MimeEntry("ttf", "font/ttf", Category.FONT, "TrueType font"),
            new MimeEntry("otf", "font/otf", Category.FONT, "OpenType font"),
            new MimeEntry("eot", "application/vnd.ms-fontobject", Category.APPLICATION, "Embedded OpenType"),

            // ── multipart ───────────────────────────────────────────────
            new MimeEntry("mht", "multipart/related", Category.MULTIPART, "MHTML web archive"),
            new MimeEntry("mhtml", "multipart/related", Category.MULTIPART, "MHTML web archive"));

    private MimeTypes() {}

    /** Lowercase an extension and drop a leading dot so ".JSON" == "json". */
    public static String normalizeExt(String ext) {
        String e = ext.trim().toLowerCase(Locale.ROOT);
        // replaceFirst drops one or more leading dots, matching /^\.+/
        return e.replaceFirst("^\\.+", "");
    }

    /**
     * Every entry whose extension matches. The dot is optional and matching
     * is case-insensitive, so ".js", "JS", and "js" are equivalent.
     * Returns an empty list for an unknown/empty extension.
     */
    public static List<MimeEntry> lookupByExt(String ext) {
        String e = normalizeExt(ext);
        if (e.isEmpty()) return List.of();
        return MIME.stream().filter(m -> m.ext().equals(e)).toList();
    }

    /**
     * Every entry whose MIME matches, case-insensitively, tolerating
     * surrounding whitespace. One MIME commonly maps to several extensions
     * (image/jpeg → jpg, jpeg), so all are returned. Empty for unknown/empty.
     */
    public static List<MimeEntry> lookupByMime(String mime) {
        String m = mime.trim().toLowerCase(Locale.ROOT);
        if (m.isEmpty()) return List.of();
        return MIME.stream().filter(e -> e.mime().toLowerCase(Locale.ROOT).equals(m)).toList();
    }

    /** Optional constraints — null fields are ignored, mirroring
     *  {@code undefined} fields in the TypeScript source. */
    public record MimeFilter(Category type, String query) {
        public static MimeFilter of() { return new MimeFilter(null, null); }
    }

    /**
     * Filter the full table by category and/or a free-text query matched
     * (case-insensitively) against ext, mime, and name. Omitted options are
     * ignored; an empty query returns the category-filtered set unchanged.
     * An unknown category value yields nothing (it is not silently coerced).
     */
    public static List<MimeEntry> filter(MimeFilter opts) {
        String q = (opts.query() == null ? "" : opts.query()).trim().toLowerCase(Locale.ROOT);
        return MIME.stream()
                .filter(e -> opts.type() == null || e.type() == opts.type())
                .filter(e -> q.isEmpty()
                        || e.ext().contains(q)
                        || e.mime().toLowerCase(Locale.ROOT).contains(q)
                        || e.name().toLowerCase(Locale.ROOT).contains(q))
                .toList();
    }

    public static void main(String[] args) {
        lookupByExt(".JSON").forEach(e ->
                System.out.printf(".JSON -> %s (%s)%n", e.mime(), e.name()));
        lookupByMime("IMAGE/JPEG").forEach(e ->
                System.out.printf("image/jpeg -> .%s%n", e.ext()));
        System.out.printf("query \"font\": %d of %d entries%n",
                filter(new MimeFilter(null, "font")).size(), MIME.size());
    }
}

Also available in 13 other languages

Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →