public byte[] getFileBytes(Long fileId) {
Fileinfo fileinfo = (Fileinfo)this.getById(fileId);
if (fileinfo == null) {
return null;
} else {
FileStorage var10000 = StorageFactory.me().getFileStorage(fileinfo.getFileLocation());
String var10001 = fileinfo.getFileBucket();
String var10002 = fileinfo.getFileUrl();
byte[] ret = var10000.getFileBytes(var10001, var10002 + fileinfo.getFileFinalName());
this.fileInfoService.uploadFileRemove(fileinfo);
return ret;
}
}
public List<Fileinfo> getFileinfos(List<Long> fileIds) {
if (CollUtil.isEmpty(fileIds)) {
return null;
} else {
List<Fileinfo> fileinfos = this.listByIds(fileIds);
if (CollUtil.isEmpty(fileinfos)) {
return null;
} else {
fileinfos.forEach((fileinfo) -> {
FileStorage var10001 = StorageFactory.me().getFileStorage(fileinfo.getFileLocation());
String var10002 = fileinfo.getFileBucket();
String var10003 = fileinfo.getFileUrl();
fileinfo.setFileUrl(var10001.getPreviewUrl(var10002, var10003 + fileinfo.getFileFinalName()));
});
return fileinfos;
}
}
}
/**
* 文字コードチェック
*
* @param charCode 文字コード
*/
private static boolean isSJIS(byte[] charCode) {
try {
byte[] tmp = new String(charCode, "Shift_JIS").getBytes("Shift_JIS");
byte[] tmp1 = new String(charCode, "MS932").getBytes("MS932");
return Arrays.equals(tmp, charCode) || Arrays.equals(tmp1, charCode);
} catch (UnsupportedEncodingException e) {
return false;
}
}
List<Fileinfo> fileinfos = getFileInfos(param.getFileIds());
byte[] fileBytes = getFileBytes(fileIds.get(i));
String fileName = fileNames.get(i).split("/")[1];
AutoDetectReader detectReader = new AutoDetectReader(new ByteArrayInputStream(fileBytes));
String coding = detectReader.getCharset().name();
boolean bshiftjis = isSJIS(fileBytes);
if (!bshiftjis) {
log.info("文字コードチェック");
break;
}
2023-02-16 java 文字コードチェック
于 2023-02-16 13:59:24 首次发布