依据文件名后缀获取MimeType
import java.util.HashMap;
import java.util.Map;
/**
* 依据文件名后缀获取MimeType
*/
public class MimeTypeUtils {
private static Map<String, String> mapMimeType = new HashMap<String, String>();
/**
* 依据文件名后缀获取MimeType
* @param suffix
* @return
*/
public static String getType(String suffix) {
if (suffix==null||suffix.length()<1){
//抛出异常
//throw new BizException(BizMessage.FILE_TYPE_ERROR);
}
String type = mapMimeType.get(suffix.toLowerCase());
if (type == null || "".equals(type)) {
//抛出异常
//throw new BizException(BizMessage.FILE_TYPE_ERROR);
}
return type;
}
private MimeTypeUtils() {
}
static {
mapMimeType.put("123", "application/vnd.lotus-1-2-3");
mapMimeType.put("3gp", "video/3gpp");
mapMimeType.put("aab", "application/x-authoware-bin");
mapMimeType.put("aam", "application/x-authoware-map");
mapMimeType.put("aas", "application/x-authoware-seg");
mapMimeType.put("ai", "application/postscript");
mapMimeType.put("aif", "audio/x-aiff");
mapMimeType.put("aifc", "audio/x-aiff");
mapMimeType.put("aiff", "audio/x-aiff");
mapMimeType.put("als", "audio/X-Alpha5");
mapMimeType.put("amc", "application/x-mpeg");
mapMimeType.put("ani", "application/octet-stream");
mapMimeType.put("asc", "text/plain");
mapMimeType.put("asd", "application/astound");
mapMimeType.put("asf", "video/x-ms-asf");
mapMimeType.put("asn", "application/astound");
mapMimeType.put("asp", "application/x-asap");
mapMimeType.put("asx", "video/x-ms-asf");
mapMimeType.put("au", "audio/basic");
mapMimeType.put("avb", "application/octet-stream");
mapMimeType.put("avi", "video/x-msvideo");
mapMimeType.put("awb", "audio/amr-wb");
mapMimeType.put("bcpio", "application/x-bcpio");
mapMimeType.put("bin", "application/octet-stream");
mapMimeType.put("bld", "application/bld");
mapMimeType.put("bld2", "application/bld2");