|
@@ -34,8 +34,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
try {
|
|
try {
|
|
ossClient.putObject(bucket, remoteFilePath, new ByteArrayInputStream(data));
|
|
ossClient.putObject(bucket, remoteFilePath, new ByteArrayInputStream(data));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("oss上传文件失败", e);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn("oss上传文件失败,remoteFilePath:" + remoteFilePath, e);
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -49,9 +48,9 @@ public class OssFileService extends AbstractFYunFileService {
|
|
public String uploadFile(String bucket, InputStream inputStream, String remoteFilePath) {
|
|
public String uploadFile(String bucket, InputStream inputStream, String remoteFilePath) {
|
|
try {
|
|
try {
|
|
ossClient.putObject(bucket, remoteFilePath, inputStream);
|
|
ossClient.putObject(bucket, remoteFilePath, inputStream);
|
|
- log.info("文件流上传成功,目标路径:path:{}", remoteFilePath);
|
|
|
|
|
|
+ log.info("文件流上传成功,目标路径:remoteFilePath:{}", remoteFilePath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("oss上传文件失败", e);
|
|
|
|
|
|
+ log.warn("oss上传文件失败,remoteFilePath:"+remoteFilePath, e);
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
@@ -62,7 +61,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
try {
|
|
try {
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
if (!file.exists()) {
|
|
if (!file.exists()) {
|
|
- log.error("要上传的文件不存在:" + filePath);
|
|
|
|
|
|
+ log.warn("要上传的文件不存在,filePath" + filePath);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
@@ -83,8 +82,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
ossClient.putObject(bucket, remoteFilePath, file, metadata);
|
|
ossClient.putObject(bucket, remoteFilePath, file, metadata);
|
|
log.info("文件上传成功,path:{}", filePath);
|
|
log.info("文件上传成功,path:{}", filePath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("oss上传文件失败", e);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn("oss上传文件失败,filePath:"+filePath, e);
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -96,9 +94,9 @@ public class OssFileService extends AbstractFYunFileService {
|
|
String command = String.format(fYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
|
|
String command = String.format(fYunConstants.UPLOAD_SH, bucket, filePath, remoteFilePath, FYunTypeEnum.OSS.code(), optType);
|
|
log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
log.info("开始上传文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
callshell(command);
|
|
callshell(command);
|
|
|
|
+ log.info("上传文件完毕, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn(String.format("上传文件失败, ossPath:%s, srcPath:%s", remoteFilePath, filePath), e);
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -110,9 +108,9 @@ public class OssFileService extends AbstractFYunFileService {
|
|
String command = String.format(fYunConstants.DOWNLOAD_SH, bucket, remoteFilePath, filePath, FYunTypeEnum.OSS.code(), optType);
|
|
String command = String.format(fYunConstants.DOWNLOAD_SH, bucket, remoteFilePath, filePath, FYunTypeEnum.OSS.code(), optType);
|
|
log.info("开始下载文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
log.info("开始下载文件, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
callshell(command);
|
|
callshell(command);
|
|
|
|
+ log.info("下载文件完毕, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("下载文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn(String.format("下载文件失败, ossPath:%s, srcPath:%s", remoteFilePath, filePath), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -121,8 +119,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
try {
|
|
try {
|
|
ossClient.deleteObject(bucket, remoteFilePath);
|
|
ossClient.deleteObject(bucket, remoteFilePath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("OSS删除文件失败,key=" + remoteFilePath);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.error("OSS删除文件失败,key:" + remoteFilePath, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -137,8 +134,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
request.setKeys(remoteFiles);
|
|
request.setKeys(remoteFiles);
|
|
ossClient.deleteObjects(request);
|
|
ossClient.deleteObjects(request);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("OSS删除文件失败,key=" + remoteFolderPath);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn("OSS删除文件失败,key:" + remoteFolderPath, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -149,7 +145,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
uploadFile(bucket, entry.getKey(), entry.getValue(), null);
|
|
uploadFile(bucket, entry.getKey(), entry.getValue(), null);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("OSS批量上传文件失败!");
|
|
|
|
|
|
+ log.warn("OSS批量上传文件失败!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -178,8 +174,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
flag = objectListing.isTruncated();
|
|
flag = objectListing.isTruncated();
|
|
} while (flag);
|
|
} while (flag);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("获取文件列表失败,path=" + sourcePath, e);
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.warn("获取文件列表失败,path:" + sourcePath, e);
|
|
}
|
|
}
|
|
return keyList;
|
|
return keyList;
|
|
}
|
|
}
|
|
@@ -195,7 +190,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
ossClient.copyObject(sourceBucketName, file, targetBucketName, file.replace(sourcePath, targetPath));
|
|
ossClient.copyObject(sourceBucketName, file, targetBucketName, file.replace(sourcePath, targetPath));
|
|
});
|
|
});
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("列举文件目录失败,key=" + sourcePath);
|
|
|
|
|
|
+ log.warn("列举文件目录失败,key:" + sourcePath, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -209,14 +204,13 @@ public class OssFileService extends AbstractFYunFileService {
|
|
copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
|
|
copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("批量复制文件失败!");
|
|
|
|
|
|
+ log.warn(String.format("批量复制文件失败, sourceBucketName:%s, targetBucketName:%s", sourceBucketName, targetBucketName), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String getFileContent(String bucketName, String remoteFilePath) {
|
|
public String getFileContent(String bucketName, String remoteFilePath) {
|
|
- try {
|
|
|
|
- OSSObject ossObject = ossClient.getObject(bucketName, remoteFilePath);
|
|
|
|
|
|
+ try (OSSObject ossObject = ossClient.getObject(bucketName, remoteFilePath)){
|
|
InputStream objectContent = ossObject.getObjectContent();
|
|
InputStream objectContent = ossObject.getObjectContent();
|
|
StringBuilder contentJson = new StringBuilder();
|
|
StringBuilder contentJson = new StringBuilder();
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(objectContent))) {
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(objectContent))) {
|
|
@@ -226,14 +220,13 @@ public class OssFileService extends AbstractFYunFileService {
|
|
contentJson.append(line);
|
|
contentJson.append(line);
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- log.error("读取文件流失败,{}", remoteFilePath, e);
|
|
|
|
|
|
+ throw e;
|
|
}
|
|
}
|
|
- ossObject.close();
|
|
|
|
return contentJson.toString();
|
|
return contentJson.toString();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("获取文件内容失败:{}", remoteFilePath);
|
|
|
|
- return null;
|
|
|
|
|
|
+ log.warn("获取文件内容失败:key:"+remoteFilePath, e);
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -241,9 +234,9 @@ public class OssFileService extends AbstractFYunFileService {
|
|
try {
|
|
try {
|
|
return ossClient.doesObjectExist(bucket, objectName);
|
|
return ossClient.doesObjectExist(bucket, objectName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("判断文件是否存在失败:{}", objectName);
|
|
|
|
- return false;
|
|
|
|
|
|
+ log.warn("判断文件是否存在失败,key:"+objectName, e);
|
|
}
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -266,8 +259,7 @@ public class OssFileService extends AbstractFYunFileService {
|
|
request.setEnableCheckpoint(true);
|
|
request.setEnableCheckpoint(true);
|
|
ossClient.downloadFile(request);
|
|
ossClient.downloadFile(request);
|
|
} catch (Throwable throwable) {
|
|
} catch (Throwable throwable) {
|
|
- log.error("文件下载失败:{}", remoteFilePath);
|
|
|
|
- throwable.printStackTrace();
|
|
|
|
|
|
+ log.warn("文件下载失败,key:"+remoteFilePath, throwable);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|