Merge branch 'feature/fix-sonar-issue-07-01' into 'master'

sonar-fix

See merge request universal/infrastructure/backend/oss!152
This commit is contained in:
徐大伟 2024-07-03 05:40:48 +00:00
commit 8f4748e3de
4 changed files with 5 additions and 8 deletions

View File

@ -399,8 +399,7 @@ public class AliOssServiceImpl implements AliOssService {
@Override
public String uploadByUrl(String bucketName, String tgtFileKey, String fileName, String url) {
OSS client = aliOssClient.getClient();
try {
InputStream srcStream = new URL(url).openStream();
try(InputStream srcStream = new URL(url).openStream()) {
// 创建上传文件的元信息通过文件云信息设置HTTP Header
ObjectMetadata metadata = new ObjectMetadata();
// 设置内容被下载时的名称

View File

@ -438,8 +438,7 @@ public class HuaWeiCloudServiceImpl implements HuaWeiCloudService {
@Override
public String uploadFileByUrl(String bucketName, String key, String fileName, String url) {
ObsClient obsClient = huaWeiCloudObsClient.getClient();
try {
InputStream srcStream = new URL(url).openStream();
try (InputStream srcStream = new URL(url).openStream()) {
// 创建上传文件的元信息通过文件云信息设置HTTP Header
ObjectMetadata metadata = new ObjectMetadata();
// 设置内容被下载时的名称

View File

@ -232,8 +232,10 @@ public class FileManagerImpl implements FileManager {
switch (typeEnum) {
case OBS:// 华为云
huaWeiCloudService.deleteFile(bucketName, key);
break;
case OSS:// 阿里云
aliOssService.deleteFile(bucketName, key);
break;
default:
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
}

View File

@ -40,11 +40,8 @@ public class FileServiceTest extends SpringTestBase {
File file = new File("/Users/admin/Downloads/表扬人员名称.xlsx");
FileInputStream fileInputStream = null;
byte[] bytes = new byte[(int) file.length()];
try {
fileInputStream = new FileInputStream(file);
try (FileInputStream fileInputStream = new FileInputStream(file)) {
fileInputStream.read(bytes);
} catch (FileNotFoundException e) {
e.printStackTrace();