java文件类型判断的工具类

文件类型判断的工具类

 package com.zmt.taobaoke.utils;
import java.io.File;

import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Component
public class CommonUtil {
	
	
	public static final String USERHEADIMAGE="http://ozfv6dq4s.bkt.clouddn.com/0";
	 /**
     * MultipartFile 转换成File
     *
     * @param multfile 原文件类型
     * @return File
     * @throws IOException
     */
    public static File multipartToFile(MultipartFile multfile) {

        CommonsMultipartFile cf = (CommonsMultipartFile)multfile;
        //这个myfile是MultipartFile的
        DiskFileItem fi = (DiskFileItem) cf.getFileItem();
        File file = fi.getStoreLocation();
        return file;
    }
    
    /**
     * 图片格式判断
     * @param perfix
     * @return
     */
    public static boolean imageType(String perfix) {
    	if(perfix.equalsIgnoreCase("JPG") || perfix.equalsIgnoreCase("JPEG") || perfix.equalsIgnoreCase("GIF")
				|| perfix.equalsIgnoreCase("PNG") || perfix.equalsIgnoreCase("BMP") || perfix.equalsIgnoreCase("PCX")
				|| perfix.equalsIgnoreCase("TGA") || perfix.equalsIgnoreCase("PSD") || perfix.equalsIgnoreCase("TIFF"))
    		return true;
    	else
    		return false;
    }
    
    /**
     * 2017-11-16 09:48:22 张
     * 
     * 音频格式判断
     * @param perfix
     * @return
     */
    public static boolean audioType(String perfix) {
    	if(perfix.equalsIgnoreCase("mp3") || perfix.equalsIgnoreCase("OGG") || perfix.equalsIgnoreCase("WAV")
				|| perfix.equalsIgnoreCase("REAL") || perfix.equalsIgnoreCase("APE") || perfix.equalsIgnoreCase("MODULE")
				|| perfix.equalsIgnoreCase("MIDI") || perfix.equalsIgnoreCase("VQF") || perfix.equalsIgnoreCase("CD")) {
    		return true;
    	}else {
    		return false;
    	}
    }
    
    /**
     * 视频格式判断
     * @return
     */
    public static boolean videoType(String perfix) {
    	if(perfix.equalsIgnoreCase("mp4") || perfix.equalsIgnoreCase("avi") || perfix.equalsIgnoreCase("MPEG-1")
				|| perfix.equalsIgnoreCase("RM") || perfix.equalsIgnoreCase("ASF") || perfix.equalsIgnoreCase("WMV")
				|| perfix.equalsIgnoreCase("qlv") || perfix.equalsIgnoreCase("MPEG-2") || perfix.equalsIgnoreCase("MPEG4")
				|| perfix.equalsIgnoreCase("mov") || perfix.equalsIgnoreCase("3gp"))
    		return true;
    	else
    		return false;
    }
    

}

你可能感兴趣的:(工具类)