验证中...
Languages: Java
Categories: Web开发技术
Latest update 2019-06-25 10:26
MIMETypeEnum
Raw Copy
/**
* MIMETypeEnum
* @author dolyw.com
* @date 2019/6/25 9:41
*/
public enum MIMETypeEnum {
// 文档文件类型的
AI("ai", "application/postscript"),
EPS("eps", "application/postscript"),
EXE("exe", "application/octet-stream"),
DOC("doc", "application/msword"),
DOT("dot", "application/msword"),
XLS("xls", "application/vnd.ms-excel"),
PPT("ppt", "application/vnd.ms-powerpoint"),
PPTX("pptx", "application/vnd.ms-powerpoint"),
PPS("pps", "application/msword"),
PDF("pdf", "application/pdf"),
XML("xml", "application/xml"),
ODT("odt", "application/vnd.oasis.opendocument.text"),
SWF("swf", "application/x-shockwave-flash"),
DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
WPS("wps", "application/vnd.ms-works"),
// 压缩文件类型的
GZ("gz", "application/x-gzip"),
TGZ("tgz", "application/x-gzip"),
BZ("bz", "application/x-bzip2"),
BZ2("bz2", "application/x-bzip2"),
TBZ("tbz", "application/x-bzip2"),
ZIP("zip", "application/zip"),
RAR("rar", "application/x-rar-compressed"),
TAR("tar", "application/x-tar"),
SEVENZ("7z", "application/x-7z-compressed"),
// 文字类型
TXT("txt", "text/plain"),
PHP("php", "text/x-php"),
HTML("html", "text/html"),
HTM("htm", "text/html"),
JS("js", "text/javascript"),
CSS("css", "text/css"),
RTF("rtf", "text/rtf"),
RTFD("rtfd", "text/rtfd"),
PY("py", "text/x-python"),
JAVA("java", "text/x-java-source"),
RB("rb", "text/x-ruby"),
SH("sh", "text/x-shellscript"),
PL("pl", "text/x-perl"),
SQL("sql", "text/x-sql"),
// 图片类型的
BMP("bmp", "image/x-ms-bmp"),
JPG("jpg", "image/jpeg"),
JPEG("jpeg", "image/jpeg"),
JPE("jpe", "image/jpeg"),
GIF("gif", "image/gif"),
PNG("png", "image/png"),
TIF("tif", "image/tiff"),
TIFF("tiff", "image/tiff"),
TGA("tga", "image/x-targa"),
PSD("psd", "image/vnd.adobe.photoshop"),
// 音频文件类型的
MP3("mp3", "audio/mpeg"),
MID("mid", "audio/midi"),
OGG("ogg", "audio/ogg"),
MP4A("mp4a", "audio/mp4"),
WAV("wav", "audio/wav"),
WMA("wma", "audio/x-ms-wma"),
// 视频文件类型的
AVI("avi", "video/x-msvideo"),
DV("dv", "video/x-dv"),
MP4("mp4", "video/mp4"),
MPEG("mpeg", "video/mpeg"),
MPG("mpg", "video/mpeg"),
MOV("mov", "video/quicktime"),
WM("wm", "video/x-ms-wmv"),
FLV("flv", "video/x-flv"),
MKV("mkv", "video/x-matroska");
private String suffix;
private String MIMEType;
MIMETypeEnum(final String suffix, final String MIMEType) {
this.suffix = suffix;
this.MIMEType = MIMEType;
}
public String getSuffix() {
return suffix;
}
public String getMIMEType() {
return MIMEType;
}
}
操作
Raw Copy
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
String mimeType = "application/zip";
for (MIMETypeEnum MIMETypeEnum : MIMETypeEnum.values()) {
if (MIMETypeEnum.getSuffix().equals(suffix)) {
mimeType = MIMETypeEnum.getMIMEType();
}
}
response.setContentType(mimeType);

Comment list( 0 )

You need to Sign in for post a comment

Help Search

183227_9af5e6a8_1826025 111910_4d91f001_1826025