Rev 23780 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.util;import java.io.File;import java.io.IOException;import org.apache.tika.Tika;import com.spice.profitmandi.common.enumuration.ContentType;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;public class FileUtil {public static ContentType detectFileType(File file) throws ProfitMandiBusinessException{Tika tika = new Tika();//detecting the file type using detect methodString filetype;try {filetype = tika.detect(file);} catch (IOException e) {e.printStackTrace();throw new ProfitMandiBusinessException("Content-Type", file.getName(), "");}if(filetype.contains("pdf")){return ContentType.PDF;}else if(filetype.contains("jpg") | filetype.contains("jpeg")){return ContentType.JPEG;}else if(filetype.contains("png")){return ContentType.PNG;}else{throw new ProfitMandiBusinessException("Content-Type", file.getName(), "");}}public static void main(String[] args){//detectFileType(new File("/hsps-docs/1499163441532"));//System.out.println("he");}}