(InputStream stream)
| 13 | |
| 14 | //apache大法 |
| 15 | public static Msg FileMiME(InputStream stream){ |
| 16 | final Msg msg = new Msg(); |
| 17 | try { |
| 18 | Tika tika = new Tika(); |
| 19 | String fileType = tika.detect(stream); |
| 20 | if (fileType != null && fileType.contains("/")) { |
| 21 | if(fileType.contains("image/")){ |
| 22 | msg.setData(fileType); |
| 23 | }else{ |
| 24 | //非图像类型 |
| 25 | msg.setCode("110602"); |
| 26 | msg.setInfo("该文件非图像文件,或不受支持"); |
| 27 | } |
| 28 | } |
| 29 | } catch (Exception e) { |
| 30 | System.err.println("这是一个图像类别鉴定的报错:161"); |
| 31 | msg.setCode("110603");//图像格式不受支持 |
| 32 | msg.setInfo("暂时不能上传该文件"); |
| 33 | } |
| 34 | return msg; |
| 35 | } |
| 36 | |
| 37 | |
| 38 |
no test coverage detected