|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Oracle and/or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.helidon.build.common; |
| 17 | + |
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.Map; |
| 20 | +import java.util.Optional; |
| 21 | + |
| 22 | +/** |
| 23 | + * Mapping of file extension to mime-type. |
| 24 | + */ |
| 25 | +public final class MediaTypes { |
| 26 | + |
| 27 | + private static final Map<String, String> MEDIA_TYPES = new HashMap<>(); |
| 28 | + |
| 29 | + static { |
| 30 | + MEDIA_TYPES.put("3gp", "video/3gpp"); |
| 31 | + MEDIA_TYPES.put("3g2", "video/3gpp2"); |
| 32 | + MEDIA_TYPES.put("7z", "application/x-7z-compressed"); |
| 33 | + MEDIA_TYPES.put("aac", "audio/aac"); |
| 34 | + MEDIA_TYPES.put("abs", "audio/x-mpeg"); |
| 35 | + MEDIA_TYPES.put("abw", "application/x-abiword"); |
| 36 | + MEDIA_TYPES.put("ai", "application/postscript"); |
| 37 | + MEDIA_TYPES.put("aif", "audio/x-aiff"); |
| 38 | + MEDIA_TYPES.put("aifc", "audio/x-aiff"); |
| 39 | + MEDIA_TYPES.put("aiff", "audio/x-aiff"); |
| 40 | + MEDIA_TYPES.put("aim", "application/x-aim"); |
| 41 | + MEDIA_TYPES.put("arc", "application/x-freearc"); |
| 42 | + MEDIA_TYPES.put("art", "image/x-jg"); |
| 43 | + MEDIA_TYPES.put("asf", "video/x-ms-asf"); |
| 44 | + MEDIA_TYPES.put("asx", "video/x-ms-asf"); |
| 45 | + MEDIA_TYPES.put("au", "audio/basic"); |
| 46 | + MEDIA_TYPES.put("avi", "video/x-msvideo"); |
| 47 | + MEDIA_TYPES.put("avx", "video/x-rad-screenplay"); |
| 48 | + MEDIA_TYPES.put("azw", "application/vnd.amazon.ebook"); |
| 49 | + MEDIA_TYPES.put("bcpio", "application/x-bcpio"); |
| 50 | + MEDIA_TYPES.put("bin", "application/octet-stream"); |
| 51 | + MEDIA_TYPES.put("bmp", "image/bmp"); |
| 52 | + MEDIA_TYPES.put("body", "text/html"); |
| 53 | + MEDIA_TYPES.put("bz", "application/x-bzip"); |
| 54 | + MEDIA_TYPES.put("bz2", "application/x-bzip2"); |
| 55 | + MEDIA_TYPES.put("cdf", "application/x-cdf"); |
| 56 | + MEDIA_TYPES.put("cer", "application/x-x509-ca-cert"); |
| 57 | + MEDIA_TYPES.put("class", "application/java"); |
| 58 | + MEDIA_TYPES.put("conf", "application/hocon"); |
| 59 | + MEDIA_TYPES.put("cpio", "application/x-cpio"); |
| 60 | + MEDIA_TYPES.put("csh", "application/x-csh"); |
| 61 | + MEDIA_TYPES.put("css", "text/css"); |
| 62 | + MEDIA_TYPES.put("csv", "text/csv"); |
| 63 | + MEDIA_TYPES.put("dib", "image/bmp"); |
| 64 | + MEDIA_TYPES.put("doc", "application/msword"); |
| 65 | + MEDIA_TYPES.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
| 66 | + MEDIA_TYPES.put("dtd", "application/xml-dtd"); |
| 67 | + MEDIA_TYPES.put("dv", "video/x-dv"); |
| 68 | + MEDIA_TYPES.put("dvi", "application/x-dvi"); |
| 69 | + MEDIA_TYPES.put("eot", "application/vnd.ms-fontobject"); |
| 70 | + MEDIA_TYPES.put("epub", "application/epub+zip"); |
| 71 | + MEDIA_TYPES.put("eps", "application/postscript"); |
| 72 | + MEDIA_TYPES.put("etx", "text/x-setext"); |
| 73 | + MEDIA_TYPES.put("exe", "application/octet-stream"); |
| 74 | + MEDIA_TYPES.put("gif", "image/gif"); |
| 75 | + MEDIA_TYPES.put("gk", "application/octet-stream"); |
| 76 | + MEDIA_TYPES.put("gtar", "application/x-gtar"); |
| 77 | + MEDIA_TYPES.put("gz", "application/gzip"); |
| 78 | + MEDIA_TYPES.put("hdf", "application/x-hdf"); |
| 79 | + MEDIA_TYPES.put("hqx", "application/mac-binhex40"); |
| 80 | + MEDIA_TYPES.put("htc", "text/x-component"); |
| 81 | + MEDIA_TYPES.put("htm", "text/html"); |
| 82 | + MEDIA_TYPES.put("html", "text/html"); |
| 83 | + MEDIA_TYPES.put("ief", "image/ief"); |
| 84 | + MEDIA_TYPES.put("ico", "image/x-icon"); |
| 85 | + MEDIA_TYPES.put("ics", "text/calendar"); |
| 86 | + MEDIA_TYPES.put("jad", "text/vnd.sun.j2me.app-descriptor"); |
| 87 | + MEDIA_TYPES.put("jar", "application/java-archive"); |
| 88 | + MEDIA_TYPES.put("java", "text/plain"); |
| 89 | + MEDIA_TYPES.put("jnlp", "application/x-java-jnlp-file"); |
| 90 | + MEDIA_TYPES.put("jpe", "image/jpeg"); |
| 91 | + MEDIA_TYPES.put("jpeg", "image/jpeg"); |
| 92 | + MEDIA_TYPES.put("jpg", "image/jpeg"); |
| 93 | + MEDIA_TYPES.put("js", "text/javascript"); |
| 94 | + MEDIA_TYPES.put("json", "application/json"); |
| 95 | + MEDIA_TYPES.put("jsonld", "application/ld+json"); |
| 96 | + MEDIA_TYPES.put("kar", "audio/x-midi"); |
| 97 | + MEDIA_TYPES.put("latex", "application/x-latex"); |
| 98 | + MEDIA_TYPES.put("m3u", "audio/x-mpegurl"); |
| 99 | + MEDIA_TYPES.put("mac", "image/x-macpaint"); |
| 100 | + MEDIA_TYPES.put("man", "application/x-troff-man"); |
| 101 | + MEDIA_TYPES.put("mathml", "application/mathml+xml"); |
| 102 | + MEDIA_TYPES.put("me", "application/x-troff-me"); |
| 103 | + MEDIA_TYPES.put("mid", "audio/midi"); |
| 104 | + MEDIA_TYPES.put("midi", "audio/midi"); |
| 105 | + MEDIA_TYPES.put("mif", "application/x-mif"); |
| 106 | + MEDIA_TYPES.put("mjs", "text/javascript"); |
| 107 | + MEDIA_TYPES.put("mov", "video/quicktime"); |
| 108 | + MEDIA_TYPES.put("movie", "video/x-sgi-movie"); |
| 109 | + MEDIA_TYPES.put("mp1", "audio/mpeg"); |
| 110 | + MEDIA_TYPES.put("mp2", "audio/mpeg"); |
| 111 | + MEDIA_TYPES.put("mp3", "audio/mpeg"); |
| 112 | + MEDIA_TYPES.put("mpa", "audio/mpeg"); |
| 113 | + MEDIA_TYPES.put("mpe", "video/mpeg"); |
| 114 | + MEDIA_TYPES.put("mpeg", "video/mpeg"); |
| 115 | + MEDIA_TYPES.put("mpega", "audio/mpeg"); |
| 116 | + MEDIA_TYPES.put("mpkg", "application/vnd.apple.installer+xml"); |
| 117 | + MEDIA_TYPES.put("mpg", "video/mpeg"); |
| 118 | + MEDIA_TYPES.put("mpv2", "video/mpeg2"); |
| 119 | + MEDIA_TYPES.put("ms", "application/x-wais-source"); |
| 120 | + MEDIA_TYPES.put("nc", "application/x-netcdf"); |
| 121 | + MEDIA_TYPES.put("oda", "application/oda"); |
| 122 | + MEDIA_TYPES.put("odp", "application/vnd.oasis.opendocument.presentation"); |
| 123 | + MEDIA_TYPES.put("ods", "application/vnd.oasis.opendocument.spreadsheet"); |
| 124 | + MEDIA_TYPES.put("odt", "application/vnd.oasis.opendocument.text"); |
| 125 | + MEDIA_TYPES.put("oga", "audio/ogg"); |
| 126 | + MEDIA_TYPES.put("ogg", "application/ogg"); |
| 127 | + MEDIA_TYPES.put("ogv", "video/ogg"); |
| 128 | + MEDIA_TYPES.put("ogx", "application/ogg"); |
| 129 | + MEDIA_TYPES.put("opus", "audio/opus"); |
| 130 | + MEDIA_TYPES.put("otf", "font/otf"); |
| 131 | + MEDIA_TYPES.put("pbm", "image/x-portable-bitmap"); |
| 132 | + MEDIA_TYPES.put("pct", "image/pict"); |
| 133 | + MEDIA_TYPES.put("pdf", "application/pdf"); |
| 134 | + MEDIA_TYPES.put("pgm", "image/x-portable-graymap"); |
| 135 | + MEDIA_TYPES.put("php", "appliction/php"); |
| 136 | + MEDIA_TYPES.put("pic", "image/pict"); |
| 137 | + MEDIA_TYPES.put("pict", "image/pict"); |
| 138 | + MEDIA_TYPES.put("pls", "audio/x-scpls"); |
| 139 | + MEDIA_TYPES.put("png", "image/png"); |
| 140 | + MEDIA_TYPES.put("pnm", "image/x-portable-anymap"); |
| 141 | + MEDIA_TYPES.put("pnt", "image/x-macpaint"); |
| 142 | + MEDIA_TYPES.put("ppm", "image/x-portable-pixmap"); |
| 143 | + MEDIA_TYPES.put("ppt", "application/vnd.ms-powerpoint"); |
| 144 | + MEDIA_TYPES.put("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); |
| 145 | + MEDIA_TYPES.put("properties", "text/x-java-properties"); |
| 146 | + MEDIA_TYPES.put("ps", "application/postscript"); |
| 147 | + MEDIA_TYPES.put("psd", "image/x-photoshop"); |
| 148 | + MEDIA_TYPES.put("qt", "video/quicktime"); |
| 149 | + MEDIA_TYPES.put("qti", "image/x-quicktime"); |
| 150 | + MEDIA_TYPES.put("qtif", "image/x-quicktime"); |
| 151 | + MEDIA_TYPES.put("rar", "application/x-rar-compressed"); |
| 152 | + MEDIA_TYPES.put("ras", "image/x-cmu-raster"); |
| 153 | + MEDIA_TYPES.put("rdf", "application/rdf+xml"); |
| 154 | + MEDIA_TYPES.put("rgb", "image/x-rgb"); |
| 155 | + MEDIA_TYPES.put("rm", "application/vnd.rn-realmedia"); |
| 156 | + MEDIA_TYPES.put("roff", "application/x-troff"); |
| 157 | + MEDIA_TYPES.put("rtf", "application/rtf"); |
| 158 | + MEDIA_TYPES.put("rtx", "text/richtext"); |
| 159 | + MEDIA_TYPES.put("sh", "application/x-sh"); |
| 160 | + MEDIA_TYPES.put("shar", "application/x-shar"); |
| 161 | + MEDIA_TYPES.put("shtml", "text/x-server-parsed-html"); |
| 162 | + MEDIA_TYPES.put("sit", "application/x-stuffit"); |
| 163 | + MEDIA_TYPES.put("smf", "audio/x-midi"); |
| 164 | + MEDIA_TYPES.put("snd", "audio/basic"); |
| 165 | + MEDIA_TYPES.put("src", "application/x-wais-source"); |
| 166 | + MEDIA_TYPES.put("sv4cpio", "application/x-sv4cpio"); |
| 167 | + MEDIA_TYPES.put("sv4crc", "application/x-sv4crc"); |
| 168 | + MEDIA_TYPES.put("svg", "image/svg+xml"); |
| 169 | + MEDIA_TYPES.put("svgz", "image/svg+xml"); |
| 170 | + MEDIA_TYPES.put("swf", "application/x-shockwave-flash"); |
| 171 | + MEDIA_TYPES.put("t", "application/x-troff"); |
| 172 | + MEDIA_TYPES.put("tar", "application/x-tar"); |
| 173 | + MEDIA_TYPES.put("tcl", "application/x-tcl"); |
| 174 | + MEDIA_TYPES.put("tex", "application/x-tex"); |
| 175 | + MEDIA_TYPES.put("texi", "application/x-texinfo"); |
| 176 | + MEDIA_TYPES.put("texinfo", "application/x-texinfo"); |
| 177 | + MEDIA_TYPES.put("tif", "image/tiff"); |
| 178 | + MEDIA_TYPES.put("tiff", "image/tiff"); |
| 179 | + MEDIA_TYPES.put("tr", "application/x-troff"); |
| 180 | + MEDIA_TYPES.put("ts", "video/mp2t"); |
| 181 | + MEDIA_TYPES.put("tsv", "text/tab-separated-values"); |
| 182 | + MEDIA_TYPES.put("ttf", "font/ttf"); |
| 183 | + MEDIA_TYPES.put("txt", "text/plain"); |
| 184 | + MEDIA_TYPES.put("ulw", "audio/basic"); |
| 185 | + MEDIA_TYPES.put("ustar", "application/x-ustar"); |
| 186 | + MEDIA_TYPES.put("vsd", "application/vnd.visio"); |
| 187 | + MEDIA_TYPES.put("vxml", "application/voicexml+xml"); |
| 188 | + MEDIA_TYPES.put("wav", "audio/wav"); |
| 189 | + MEDIA_TYPES.put("wbmp", "image/vnd.wap.wbmp"); |
| 190 | + MEDIA_TYPES.put("weba", "audio/webm"); |
| 191 | + MEDIA_TYPES.put("webm", "video/webm"); |
| 192 | + MEDIA_TYPES.put("webp", "image/webp"); |
| 193 | + MEDIA_TYPES.put("wml", "text/vnd.wap.wml"); |
| 194 | + MEDIA_TYPES.put("wmlc", "application/vnd.wap.wmlc"); |
| 195 | + MEDIA_TYPES.put("wmls", "text/vnd.wap.wmls"); |
| 196 | + MEDIA_TYPES.put("wmlscriptc", "application/vnd.wap.wmlscriptc"); |
| 197 | + MEDIA_TYPES.put("woff", "font/woff"); |
| 198 | + MEDIA_TYPES.put("woff2", "font/woff2"); |
| 199 | + MEDIA_TYPES.put("wrl", "x-world/x-vrml"); |
| 200 | + MEDIA_TYPES.put("xbm", "image/x-xbitmap"); |
| 201 | + MEDIA_TYPES.put("xht", "application/xhtml+xml"); |
| 202 | + MEDIA_TYPES.put("xhtml", "application/xhtml+xml"); |
| 203 | + MEDIA_TYPES.put("xls", "application/vnd.ms-excel"); |
| 204 | + MEDIA_TYPES.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| 205 | + MEDIA_TYPES.put("xml", "application/xml"); |
| 206 | + MEDIA_TYPES.put("xpm", "image/x-xpixmap"); |
| 207 | + MEDIA_TYPES.put("xsl", "application/xml"); |
| 208 | + MEDIA_TYPES.put("xslt", "application/xslt+xml"); |
| 209 | + MEDIA_TYPES.put("xul", "application/vnd.mozilla.xul+xml"); |
| 210 | + MEDIA_TYPES.put("xwd", "image/x-xwindowdump"); |
| 211 | + MEDIA_TYPES.put("yaml", "application/x-yaml"); |
| 212 | + MEDIA_TYPES.put("yml", "application/x-yaml"); |
| 213 | + MEDIA_TYPES.put("Z", "application/x-compress"); |
| 214 | + MEDIA_TYPES.put("z", "application/x-compress"); |
| 215 | + MEDIA_TYPES.put("zip", "application/zip"); |
| 216 | + } |
| 217 | + |
| 218 | + private MediaTypes() { |
| 219 | + // cannot be instanciated |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Get the media type for the given file extension. |
| 224 | + * |
| 225 | + * @param ext file extension E.g. {@code "png"} |
| 226 | + * @return optional of media type |
| 227 | + */ |
| 228 | + public static Optional<String> of(String ext) { |
| 229 | + return Optional.ofNullable(MEDIA_TYPES.get(ext)); |
| 230 | + } |
| 231 | +} |
0 commit comments