fix: 修复文件检查错误的BUG
This commit is contained in:
+2
-1
@@ -1844,6 +1844,7 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
//获取文件信息
|
||||
AttFileEO fileInfo = attFileEOService.getFileInfo(fileAttId);
|
||||
String checkResult = encryptFileUtils.checkFileIsEncryFile(fileInfo);
|
||||
logger.debug(checkResult);
|
||||
switch (checkResult){
|
||||
case "NOFILE":
|
||||
fileLog.append(" 检查结果为 不存在该数据 ");
|
||||
@@ -1858,7 +1859,7 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
||||
fileLog.setLength(0);
|
||||
break;
|
||||
case "ENCRYPT":
|
||||
fileLog.append(" 检查结果为 读取文件为空 ");
|
||||
fileLog.append(" 检查结果为 文件加密 ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -3598,6 +3598,7 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
|
||||
//获取文件信息
|
||||
AttFileEO fileInfo = attFileEOService.getFileInfo(fileAttId);
|
||||
String checkResult = encryptFileUtils.checkFileIsEncryFile(fileInfo);
|
||||
logger.debug(checkResult);
|
||||
switch (checkResult){
|
||||
case "NOFILE":
|
||||
fileLog.append(" 检查结果为 不存在该数据 ");
|
||||
@@ -3612,7 +3613,7 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
|
||||
fileLog.setLength(0);
|
||||
break;
|
||||
case "ENCRYPT":
|
||||
fileLog.append(" 检查结果为 读取文件为空 ");
|
||||
fileLog.append(" 检查结果为 文件加密 ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class EncryptFileUtils {
|
||||
}
|
||||
}
|
||||
String hexString = bytesToHexString(b);
|
||||
logger.debug(hexString);
|
||||
if(readFlag){
|
||||
if(StringUtils.isNotBlank(hexString)){
|
||||
if(StringUtils.equals(hexString,ENCRYPT_FILE_HEX)){
|
||||
@@ -67,6 +68,42 @@ public class EncryptFileUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String checkFileIsEncrypt(String readFilePath){
|
||||
boolean readFlag = true;
|
||||
byte[] b = new byte[160];
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(readFilePath);
|
||||
inputStream.read(b, 0, 160);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
readFlag = false;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
String hexString = bytesToHexString(b);
|
||||
logger.debug(hexString);
|
||||
if(readFlag){
|
||||
if(StringUtils.isNotBlank(hexString)){
|
||||
if(StringUtils.equals(hexString,ENCRYPT_FILE_HEX)){
|
||||
return "ENCRYPT";
|
||||
}else{
|
||||
return "UNENCRYPT";
|
||||
}
|
||||
}else{
|
||||
return "READNO";
|
||||
}
|
||||
}else{
|
||||
return "READERR";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件头转换成16进制字符串
|
||||
*
|
||||
@@ -89,6 +126,12 @@ public class EncryptFileUtils {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String filePath ="E:\\FOTONFILE\\sypv9xbkukd6g5fey8w1.DOC";
|
||||
String s = EncryptFileUtils.checkFileIsEncrypt(filePath);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 本地写TXT文件
|
||||
|
||||
Reference in New Issue
Block a user