fix: 修复文件检查错误的BUG
This commit is contained in:
@@ -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