Standart mim sabitlərini əks etdirən interfeys / sayım

Bütün standart mim növlərinin (aka content-type) dəyərlərini sıralayan bir interfeys və ya numaralandırma üçün standart kitabxanalara (məsələn, apache commons, jax, jboss, javax) göz atın.

Bu interfeys gwt mənbə kodu kimi bütün qrupu daxil etmək çətinləşdirən digər siniflər ilə çox mürəkkəb olmamalıdır.

məsələn

 interface ContentType{ String JSON = "Application/JSON"; blah ... blah ... } 

ya da,

 enum ContentType{ JSON("Application/JSON"), blah ... blah ... } 
77
21 окт. Blessed Geek tərəfindən 21 oktyabrda təyin olundu 2011-10-21 23:25 '11 saat 23:25 'də 2011-10-21 23:25
@ 10 cavab

Bunun üçün bir Guava klassımız var: com.google.common.net.MediaType .

Guava 12 ilə, qaynaq kodunda göstərildiyi kimi, və 823 saylıda buraxılmışdır . Kaynaklar da mövcuddur.

49
24 февр. Cavab Fabian Barney tərəfindən verilir 24 fevral. 2012-02-24 03:08 '12 at 3:08 2012-02-24 03:08
55
24 февр. Cavab 24 fevralda Ray Tayek tərəfindən verilir. 2012-02-24 04:18 '12 at 4:18 'da 2012-02-24 04:18

Bahar çərçivəsini istifadə edirsinizsə , MediaType ümumi məzmun növləri üçün mövcuddur:

  MediaType.TEXT_HTML MediaType.TEXT_PLAIN MediaType.TEXT_XML MediaType.APPLICATION_JSON MediaType.IMAGE_JPEG ... 
33
25 мая '12 в 15:56 2012-05-25 15:56 cavab 25 may 2012-ci il saat 15 : 56-da Andrejs tərəfindən verilir. 2012-05-25 15:56

İndi org.apache.http.entity.ContentType sinfi org.apache.http.entity.ContentType paketindən 4.2 yuxarıdan başlayır.

13
02 сент. cavabını daşqın verilir 02 Sentyabr. 2014-09-02 13:48 '14 da 13:48 2014-09-02 13:48

JAX-RS- dən javax.ws.rs.core.MediaType

11
22 июня '13 в 14:36 2013-06-22 14:36 Cavab Fransua Wauquier tərəfindən 22 İyun 'da saat 14:36' də verilir

Java 7 qurtarmağa!

Fayl və ya fayl adını keçə bilərsiniz və MIME növünü qaytaracaqsınız.

 String mimeType = MimetypesFileTypeMap .getDefaultFileTypeMap() .getContentType(attachment.getFileName()); 

http://docs.oracle.com/javase/7/docs/api/javax/activation/MimetypesFileTypeMap.html

6
07 сент. Cavab 07 Avqust tarixində verilir 2014-09-07 09:47 '14 da 9:47 2014-09-07 09:47

Android ilə istifadə etmək istədiyiniz halda, androidannotations bir MediaType sinif var! Buraya baxın.

4
02 мая '15 в 19:36 2015-05-02 19:36 Cavab sais kaliakoudas'a verildi 02 may '15 saat 19:36

Androiddə olursanız, bir neçə variant var ki, burada yalnız ilk "siyahı" bir növüdür:

Məsələn,

 @Override public String getType(Uri uri) { return URLConnection.getFileNameMap().getContentTypeFor( uri.getLastPathSegment()); } 
1
22 июня '15 в 21:39 2015-06-22 21:39 Cavab şagird tərəfindən 22 iyun 'da 21:39' də verilir. 2015-06-22 21:39

Bunu statik bir sinif ilə həll etdim:

 @SuppressWarnings("serial") public class MimeTypes { private static final HashMap<String, String> mimeTypes; static { mimeTypes = new HashMap<String, String>() { { put(".323", "text/h323"); put(".3g2", "video/3gpp2"); put(".3gp", "video/3gpp"); put(".3gp2", "video/3gpp2"); put(".3gpp", "video/3gpp"); put(".7z", "application/x-7z-compressed"); put(".aa", "audio/audible"); put(".AAC", "audio/aac"); put(".aaf", "application/octet-stream"); put(".aax", "audio/vnd.audible.aax"); put(".ac3", "audio/ac3"); put(".aca", "application/octet-stream"); put(".accda", "application/msaccess.addin"); put(".accdb", "application/msaccess"); put(".accdc", "application/msaccess.cab"); put(".accde", "application/msaccess"); put(".accdr", "application/msaccess.runtime"); put(".accdt", "application/msaccess"); put(".accdw", "application/msaccess.webapplication"); put(".accft", "application/msaccess.ftemplate"); put(".acx", "application/internet-property-stream"); put(".AddIn", "text/xml"); put(".ade", "application/msaccess"); put(".adobebridge", "application/x-bridge-url"); put(".adp", "application/msaccess"); put(".ADT", "audio/vnd.dlna.adts"); put(".ADTS", "audio/aac"); put(".afm", "application/octet-stream"); put(".ai", "application/postscript"); put(".aif", "audio/x-aiff"); put(".aifc", "audio/aiff"); put(".aiff", "audio/aiff"); put(".air", "application/vnd.adobe.air-application-installer-package+zip"); put(".amc", "application/x-mpeg"); put(".application", "application/x-ms-application"); put(".art", "image/x-jg"); put(".asa", "application/xml"); put(".asax", "application/xml"); put(".ascx", "application/xml"); put(".asd", "application/octet-stream"); put(".asf", "video/x-ms-asf"); put(".ashx", "application/xml"); put(".asi", "application/octet-stream"); put(".asm", "text/plain"); put(".asmx", "application/xml"); put(".aspx", "application/xml"); put(".asr", "video/x-ms-asf"); put(".asx", "video/x-ms-asf"); put(".atom", "application/atom+xml"); put(".au", "audio/basic"); put(".avi", "video/x-msvideo"); put(".axs", "application/olescript"); put(".bas", "text/plain"); put(".bcpio", "application/x-bcpio"); put(".bin", "application/octet-stream"); put(".bmp", "image/bmp"); put(".c", "text/plain"); put(".cab", "application/octet-stream"); put(".caf", "audio/x-caf"); put(".calx", "application/vnd.ms-office.calx"); put(".cat", "application/vnd.ms-pki.seccat"); put(".cc", "text/plain"); put(".cd", "text/plain"); put(".cdda", "audio/aiff"); put(".cdf", "application/x-cdf"); put(".cer", "application/x-x509-ca-cert"); put(".chm", "application/octet-stream"); put(".class", "application/x-java-applet"); put(".clp", "application/x-msclip"); put(".cmx", "image/x-cmx"); put(".cnf", "text/plain"); put(".cod", "image/cis-cod"); put(".config", "application/xml"); put(".contact", "text/x-ms-contact"); put(".coverage", "application/xml"); put(".cpio", "application/x-cpio"); put(".cpp", "text/plain"); put(".crd", "application/x-mscardfile"); put(".crl", "application/pkix-crl"); put(".crt", "application/x-x509-ca-cert"); put(".cs", "text/plain"); put(".csdproj", "text/plain"); put(".csh", "application/x-csh"); put(".csproj", "text/plain"); put(".css", "text/css"); put(".csv", "text/csv"); put(".cur", "application/octet-stream"); put(".cxx", "text/plain"); put(".dat", "application/octet-stream"); put(".datasource", "application/xml"); put(".dbproj", "text/plain"); put(".dcr", "application/x-director"); put(".def", "text/plain"); put(".deploy", "application/octet-stream"); put(".der", "application/x-x509-ca-cert"); put(".dgml", "application/xml"); put(".dib", "image/bmp"); put(".dif", "video/x-dv"); put(".dir", "application/x-director"); put(".disco", "text/xml"); put(".dll", "application/x-msdownload"); put(".dll.config", "text/xml"); put(".dlm", "text/dlm"); put(".doc", "application/msword"); put(".docm", "application/vnd.ms-word.document.macroEnabled.12"); put(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); put(".dot", "application/msword"); put(".dotm", "application/vnd.ms-word.template.macroEnabled.12"); put(".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"); put(".dsp", "application/octet-stream"); put(".dsw", "text/plain"); put(".dtd", "text/xml"); put(".dtsConfig", "text/xml"); put(".dv", "video/x-dv"); put(".dvi", "application/x-dvi"); put(".dwf", "drawing/x-dwf"); put(".dwp", "application/octet-stream"); put(".dxr", "application/x-director"); put(".eml", "message/rfc822"); put(".emz", "application/octet-stream"); put(".eot", "application/octet-stream"); put(".eps", "application/postscript"); put(".etl", "application/etl"); put(".etx", "text/x-setext"); put(".evy", "application/envoy"); put(".exe", "application/octet-stream"); put(".exe.config", "text/xml"); put(".fdf", "application/vnd.fdf"); put(".fif", "application/fractals"); put(".filters", "Application/xml"); put(".fla", "application/octet-stream"); put(".flr", "x-world/x-vrml"); put(".flv", "video/x-flv"); put(".fsscript", "application/fsharp-script"); put(".fsx", "application/fsharp-script"); put(".generictest", "application/xml"); put(".gif", "image/gif"); put(".group", "text/x-ms-group"); put(".gsm", "audio/x-gsm"); put(".gtar", "application/x-gtar"); put(".gz", "application/x-gzip"); put(".h", "text/plain"); put(".hdf", "application/x-hdf"); put(".hdml", "text/x-hdml"); put(".hhc", "application/x-oleobject"); put(".hhk", "application/octet-stream"); put(".hhp", "application/octet-stream"); put(".hlp", "application/winhlp"); put(".hpp", "text/plain"); put(".hqx", "application/mac-binhex40"); put(".hta", "application/hta"); put(".htc", "text/x-component"); put(".htm", "text/html"); put(".html", "text/html"); put(".htt", "text/webviewhtml"); put(".hxa", "application/xml"); put(".hxc", "application/xml"); put(".hxd", "application/octet-stream"); put(".hxe", "application/xml"); put(".hxf", "application/xml"); put(".hxh", "application/octet-stream"); put(".hxi", "application/octet-stream"); put(".hxk", "application/xml"); put(".hxq", "application/octet-stream"); put(".hxr", "application/octet-stream"); put(".hxs", "application/octet-stream"); put(".hxt", "text/html"); put(".hxv", "application/xml"); put(".hxw", "application/octet-stream"); put(".hxx", "text/plain"); put(".i", "text/plain"); put(".ico", "image/x-icon"); put(".ics", "application/octet-stream"); put(".idl", "text/plain"); put(".ief", "image/ief"); put(".iii", "application/x-iphone"); put(".inc", "text/plain"); put(".inf", "application/octet-stream"); put(".inl", "text/plain"); put(".ins", "application/x-internet-signup"); put(".ipa", "application/x-itunes-ipa"); put(".ipg", "application/x-itunes-ipg"); put(".ipproj", "text/plain"); put(".ipsw", "application/x-itunes-ipsw"); put(".iqy", "text/x-ms-iqy"); put(".isp", "application/x-internet-signup"); put(".ite", "application/x-itunes-ite"); put(".itlp", "application/x-itunes-itlp"); put(".itms", "application/x-itunes-itms"); put(".itpc", "application/x-itunes-itpc"); put(".IVF", "video/x-ivf"); put(".jar", "application/java-archive"); put(".java", "application/octet-stream"); put(".jck", "application/liquidmotion"); put(".jcz", "application/liquidmotion"); put(".jfif", "image/pjpeg"); put(".jnlp", "application/x-java-jnlp-file"); put(".jpb", "application/octet-stream"); put(".jpe", "image/jpeg"); put(".jpeg", "image/jpeg"); put(".jpg", "image/jpeg"); put(".js", "application/x-javascript"); put(".json", "application/json"); put(".jsx", "text/jscript"); put(".jsxbin", "text/plain"); put(".latex", "application/x-latex"); put(".library-ms", "application/windows-library+xml"); put(".lit", "application/x-ms-reader"); put(".loadtest", "application/xml"); put(".lpk", "application/octet-stream"); put(".lsf", "video/x-la-asf"); put(".lst", "text/plain"); put(".lsx", "video/x-la-asf"); put(".lzh", "application/octet-stream"); put(".m13", "application/x-msmediaview"); put(".m14", "application/x-msmediaview"); put(".m1v", "video/mpeg"); put(".m2t", "video/vnd.dlna.mpeg-tts"); put(".m2ts", "video/vnd.dlna.mpeg-tts"); put(".m2v", "video/mpeg"); put(".m3u", "audio/x-mpegurl"); put(".m3u8", "audio/x-mpegurl"); put(".m4a", "audio/m4a"); put(".m4b", "audio/m4b"); put(".m4p", "audio/m4p"); put(".m4r", "audio/x-m4r"); put(".m4v", "video/x-m4v"); put(".mac", "image/x-macpaint"); put(".mak", "text/plain"); put(".man", "application/x-troff-man"); put(".manifest", "application/x-ms-manifest"); put(".map", "text/plain"); put(".master", "application/xml"); put(".mda", "application/msaccess"); put(".mdb", "application/x-msaccess"); put(".mde", "application/msaccess"); put(".mdp", "application/octet-stream"); put(".me", "application/x-troff-me"); put(".mfp", "application/x-shockwave-flash"); put(".mht", "message/rfc822"); put(".mhtml", "message/rfc822"); put(".mid", "audio/mid"); put(".midi", "audio/mid"); put(".mix", "application/octet-stream"); put(".mk", "text/plain"); put(".mmf", "application/x-smaf"); put(".mno", "text/xml"); put(".mny", "application/x-msmoney"); put(".mod", "video/mpeg"); put(".mov", "video/quicktime"); put(".movie", "video/x-sgi-movie"); put(".mp2", "video/mpeg"); put(".mp2v", "video/mpeg"); put(".mp3", "audio/mpeg"); put(".mp4", "video/mp4"); put(".mp4v", "video/mp4"); put(".mpa", "video/mpeg"); put(".mpe", "video/mpeg"); put(".mpeg", "video/mpeg"); put(".mpf", "application/vnd.ms-mediapackage"); put(".mpg", "video/mpeg"); put(".mpp", "application/vnd.ms-project"); put(".mpv2", "video/mpeg"); put(".mqv", "video/quicktime"); put(".ms", "application/x-troff-ms"); put(".msi", "application/octet-stream"); put(".mso", "application/octet-stream"); put(".mts", "video/vnd.dlna.mpeg-tts"); put(".mtx", "application/xml"); put(".mvb", "application/x-msmediaview"); put(".mvc", "application/x-miva-compiled"); put(".mxp", "application/x-mmxp"); put(".nc", "application/x-netcdf"); put(".nsc", "video/x-ms-asf"); put(".nws", "message/rfc822"); put(".ocx", "application/octet-stream"); put(".oda", "application/oda"); put(".odc", "text/x-ms-odc"); put(".odh", "text/plain"); put(".odl", "text/plain"); put(".odp", "application/vnd.oasis.opendocument.presentation"); put(".ods", "application/oleobject"); put(".odt", "application/vnd.oasis.opendocument.text"); put(".one", "application/onenote"); put(".onea", "application/onenote"); put(".onepkg", "application/onenote"); put(".onetmp", "application/onenote"); put(".onetoc", "application/onenote"); put(".onetoc2", "application/onenote"); put(".orderedtest", "application/xml"); put(".osdx", "application/opensearchdescription+xml"); put(".p10", "application/pkcs10"); put(".p12", "application/x-pkcs12"); put(".p7b", "application/x-pkcs7-certificates"); put(".p7c", "application/pkcs7-mime"); put(".p7m", "application/pkcs7-mime"); put(".p7r", "application/x-pkcs7-certreqresp"); put(".p7s", "application/pkcs7-signature"); put(".pbm", "image/x-portable-bitmap"); put(".pcast", "application/x-podcast"); put(".pct", "image/pict"); put(".pcx", "application/octet-stream"); put(".pcz", "application/octet-stream"); put(".pdf", "application/pdf"); put(".pfb", "application/octet-stream"); put(".pfm", "application/octet-stream"); put(".pfx", "application/x-pkcs12"); put(".pgm", "image/x-portable-graymap"); put(".pic", "image/pict"); put(".pict", "image/pict"); put(".pkgdef", "text/plain"); put(".pkgundef", "text/plain"); put(".pko", "application/vnd.ms-pki.pko"); put(".pls", "audio/scpls"); put(".pma", "application/x-perfmon"); put(".pmc", "application/x-perfmon"); put(".pml", "application/x-perfmon"); put(".pmr", "application/x-perfmon"); put(".pmw", "application/x-perfmon"); put(".png", "image/png"); put(".pnm", "image/x-portable-anymap"); put(".pnt", "image/x-macpaint"); put(".pntg", "image/x-macpaint"); put(".pnz", "image/png"); put(".pot", "application/vnd.ms-powerpoint"); put(".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12"); put(".potx", "application/vnd.openxmlformats-officedocument.presentationml.template"); put(".ppa", "application/vnd.ms-powerpoint"); put(".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12"); put(".ppm", "image/x-portable-pixmap"); put(".pps", "application/vnd.ms-powerpoint"); put(".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"); put(".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"); put(".ppt", "application/vnd.ms-powerpoint"); put(".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"); put(".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); put(".prf", "application/pics-rules"); put(".prm", "application/octet-stream"); put(".prx", "application/octet-stream"); put(".ps", "application/postscript"); put(".psc1", "application/PowerShell"); put(".psd", "application/octet-stream"); put(".psess", "application/xml"); put(".psm", "application/octet-stream"); put(".psp", "application/octet-stream"); put(".pub", "application/x-mspublisher"); put(".pwz", "application/vnd.ms-powerpoint"); put(".qht", "text/x-html-insertion"); put(".qhtm", "text/x-html-insertion"); put(".qt", "video/quicktime"); put(".qti", "image/x-quicktime"); put(".qtif", "image/x-quicktime"); put(".qtl", "application/x-quicktimeplayer"); put(".qxd", "application/octet-stream"); put(".ra", "audio/x-pn-realaudio"); put(".ram", "audio/x-pn-realaudio"); put(".rar", "application/octet-stream"); put(".ras", "image/x-cmu-raster"); put(".rat", "application/rat-file"); put(".rc", "text/plain"); put(".rc2", "text/plain"); put(".rct", "text/plain"); put(".rdlc", "application/xml"); put(".resx", "application/xml"); put(".rf", "image/vnd.rn-realflash"); put(".rgb", "image/x-rgb"); put(".rgs", "text/plain"); put(".rm", "application/vnd.rn-realmedia"); put(".rmi", "audio/mid"); put(".rmp", "application/vnd.rn-rn_music_package"); put(".roff", "application/x-troff"); put(".rpm", "audio/x-pn-realaudio-plugin"); put(".rqy", "text/x-ms-rqy"); put(".rtf", "application/rtf"); put(".rtx", "text/richtext"); put(".ruleset", "application/xml"); put(".s", "text/plain"); put(".safariextz", "application/x-safari-safariextz"); put(".scd", "application/x-msschedule"); put(".sct", "text/scriptlet"); put(".sd2", "audio/x-sd2"); put(".sdp", "application/sdp"); put(".sea", "application/octet-stream"); put(".searchConnector-ms", "application/windows-search-connector+xml"); put(".setpay", "application/set-payment-initiation"); put(".setreg", "application/set-registration-initiation"); put(".settings", "application/xml"); put(".sgimb", "application/x-sgimb"); put(".sgml", "text/sgml"); put(".sh", "application/x-sh"); put(".shar", "application/x-shar"); put(".shtml", "text/html"); put(".sit", "application/x-stuffit"); put(".sitemap", "application/xml"); put(".skin", "application/xml"); put(".sldm", "application/vnd.ms-powerpoint.slide.macroEnabled.12"); put(".sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide"); put(".slk", "application/vnd.ms-excel"); put(".sln", "text/plain"); put(".slupkg-ms", "application/x-ms-license"); put(".smd", "audio/x-smd"); put(".smi", "application/octet-stream"); put(".smx", "audio/x-smd"); put(".smz", "audio/x-smd"); put(".snd", "audio/basic"); put(".snippet", "application/xml"); put(".snp", "application/octet-stream"); put(".sol", "text/plain"); put(".sor", "text/plain"); put(".spc", "application/x-pkcs7-certificates"); put(".spl", "application/futuresplash"); put(".src", "application/x-wais-source"); put(".srf", "text/plain"); put(".SSISDeploymentManifest", "text/xml"); put(".ssm", "application/streamingmedia"); put(".sst", "application/vnd.ms-pki.certstore"); put(".stl", "application/vnd.ms-pki.stl"); put(".sv4cpio", "application/x-sv4cpio"); put(".sv4crc", "application/x-sv4crc"); put(".svc", "application/xml"); put(".swf", "application/x-shockwave-flash"); put(".t", "application/x-troff"); put(".tar", "application/x-tar"); put(".tcl", "application/x-tcl"); put(".testrunconfig", "application/xml"); put(".testsettings", "application/xml"); put(".tex", "application/x-tex"); put(".texi", "application/x-texinfo"); put(".texinfo", "application/x-texinfo"); put(".tgz", "application/x-compressed"); put(".thmx", "application/vnd.ms-officetheme"); put(".thn", "application/octet-stream"); put(".tif", "image/tiff"); put(".tiff", "image/tiff"); put(".tlh", "text/plain"); put(".tli", "text/plain"); put(".toc", "application/octet-stream"); put(".tr", "application/x-troff"); put(".trm", "application/x-msterminal"); put(".trx", "application/xml"); put(".ts", "video/vnd.dlna.mpeg-tts"); put(".tsv", "text/tab-separated-values"); put(".ttf", "application/octet-stream"); put(".tts", "video/vnd.dlna.mpeg-tts"); put(".txt", "text/plain"); put(".u32", "application/octet-stream"); put(".uls", "text/iuls"); put(".user", "text/plain"); put(".ustar", "application/x-ustar"); put(".vb", "text/plain"); put(".vbdproj", "text/plain"); put(".vbk", "video/mpeg"); put(".vbproj", "text/plain"); put(".vbs", "text/vbscript"); put(".vcf", "text/x-vcard"); put(".vcproj", "Application/xml"); put(".vcs", "text/plain"); put(".vcxproj", "Application/xml"); put(".vddproj", "text/plain"); put(".vdp", "text/plain"); put(".vdproj", "text/plain"); put(".vdx", "application/vnd.ms-visio.viewer"); put(".vml", "text/xml"); put(".vscontent", "application/xml"); put(".vsct", "text/xml"); put(".vsd", "application/vnd.visio"); put(".vsi", "application/ms-vsi"); put(".vsix", "application/vsix"); put(".vsix> 
0
15 июня '17 в 17:32 2017-06-15 17:32 Cavab Trboy tərəfindən 15 İyun '17' də 17:32 2017-06-15 17:32 'də verilir

Əvvəlki cavabda dərc olunduğu kimi, ən məşhur MIME növləri bir web serverdə konfiqurasiya edilir. Məsələn, tomcat conf / web.xml aşağıdakı MIME parametrləri ilə var:

  <mime-mapping> <extension>abs</extension> <mime-type>audio/x-mpeg</mime-type> </mime-mapping> <mime-mapping> <extension>ai</extension> <mime-type>application/postscript</mime-type> </mime-mapping> <mime-mapping> <extension>aif</extension> <mime-type>audio/x-aiff</mime-type> </mime-mapping> ... 

Veb tətbiqi başlandığında işləyən başlanğıc dinləyicisi yaradın və bu XML faylını təhlil edin və sizin üçün bir ENUMS yaradır və aşağı axını paylaşmaq üçün servlet məzmunu ilə əlaqələndirir.

-2
15 февр. Cavab Bimalesh Jha 15 Fevral verilir. 2012-02-15 13:14 '12 saat 13:14 'da 2012-02-15 13:14