Commit 93dd46ff authored by luzhuang's avatar luzhuang

修改

parent d85f3c1f
...@@ -25,16 +25,16 @@ public class CheckFileHeaderUtil { ...@@ -25,16 +25,16 @@ public class CheckFileHeaderUtil {
* @param url * @param url
* @return * @return
*/ */
public boolean toCheck(String url){ public static boolean toCheck(String url){
String result = ""; String result = "";
try{ try{
FileInputStream is = new FileInputStream(url); FileInputStream is = new FileInputStream(url);
byte[] b = new byte[45]; byte[] b = new byte[45];
is.read(b, 0, b.length); is.read(b, 0, b.length);
result = this.checkType(bytesToHexString(b).toUpperCase()); result = checkType(bytesToHexString(b).toUpperCase());
is.close(); is.close();
}catch (Exception e){ }catch (Exception e){
log.debug(e.getMessage()); log.error(e.getMessage());
} }
if(result.toUpperCase().contains(url.substring(url.lastIndexOf(".")+1).toUpperCase())){ if(result.toUpperCase().contains(url.substring(url.lastIndexOf(".")+1).toUpperCase())){
return true; return true;
......
...@@ -84,6 +84,11 @@ public class FileReadableUtil { ...@@ -84,6 +84,11 @@ public class FileReadableUtil {
}catch(Exception e){ }catch(Exception e){
log.error("关闭 InputStream 输出流错误!", e); log.error("关闭 InputStream 输出流错误!", e);
} }
if (!CheckFileHeaderUtil.toCheck(path)){
throw new ServiceException(ResultServiceEnums.FILE_UNREADABLE);
}
} }
public File TXTHandler(File file) { public File TXTHandler(File file) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment