|
@@ -28,7 +28,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
private AmazonS3 s3;
|
|
private AmazonS3 s3;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadFile(String bucket, byte[] data, String remoteFilePath) throws Exception {
|
|
|
|
|
|
+ public void uploadFile(String bucket, byte[] data, String remoteFilePath){
|
|
try {
|
|
try {
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
PutObjectRequest request = new PutObjectRequest(bucket, remoteFilePath, new ByteArrayInputStream(data), metadata);
|
|
PutObjectRequest request = new PutObjectRequest(bucket, remoteFilePath, new ByteArrayInputStream(data), metadata);
|
|
@@ -44,16 +44,16 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadFile(String bucket, String filePath, String remoteFilePath) throws Exception {
|
|
|
|
|
|
+ public void uploadFile(String bucket, String filePath, String remoteFilePath){
|
|
uploadFile(bucket, filePath, remoteFilePath,true,null);
|
|
uploadFile(bucket, filePath, remoteFilePath,true,null);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) throws Exception {
|
|
|
|
|
|
+ public void uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers){
|
|
uploadFile(bucket, filePath, remoteFilePath,true,headers);
|
|
uploadFile(bucket, filePath, remoteFilePath,true,headers);
|
|
}
|
|
}
|
|
|
|
|
|
- private void uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers) throws Exception {
|
|
|
|
|
|
+ private void uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers){
|
|
try {
|
|
try {
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
if (!file.exists()) {
|
|
if (!file.exists()) {
|
|
@@ -93,7 +93,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadFileByCommand(String bucket, String filePath, String remoteFilePath) throws Exception {
|
|
|
|
|
|
+ public void uploadFileByCommand(String bucket, String filePath, String remoteFilePath){
|
|
String ossPath = bucket + "/" + remoteFilePath;
|
|
String ossPath = bucket + "/" + remoteFilePath;
|
|
try {
|
|
try {
|
|
String command = String.format(FYunConstants.UPLOAD_SH, ossPath, filePath);
|
|
String command = String.format(FYunConstants.UPLOAD_SH, ossPath, filePath);
|
|
@@ -106,7 +106,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void deleteFile(String bucket, String remoteFilePath) throws IOException {
|
|
|
|
|
|
+ public void deleteFile(String bucket, String remoteFilePath){
|
|
if (remoteFilePath.startsWith("/")) {
|
|
if (remoteFilePath.startsWith("/")) {
|
|
remoteFilePath = remoteFilePath.substring(1);
|
|
remoteFilePath = remoteFilePath.substring(1);
|
|
}
|
|
}
|
|
@@ -122,7 +122,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void deleteFolder(String bucket, String remoteFolderPath) throws Exception {
|
|
|
|
|
|
+ public void deleteFolder(String bucket, String remoteFolderPath){
|
|
try {
|
|
try {
|
|
int maxKeys = 200;
|
|
int maxKeys = 200;
|
|
String nextMaker = null;
|
|
String nextMaker = null;
|
|
@@ -156,7 +156,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void uploadMulFiles(String bucket, Map<String, String> filepaths) throws Exception {
|
|
|
|
|
|
+ public void uploadMulFiles(String bucket, Map<String, String> filepaths){
|
|
try {
|
|
try {
|
|
for (Map.Entry<String, String> entry : filepaths.entrySet()) {
|
|
for (Map.Entry<String, String> entry : filepaths.entrySet()) {
|
|
uploadFile(bucket, entry.getKey(), entry.getValue(), false,null);
|
|
uploadFile(bucket, entry.getKey(), entry.getValue(), false,null);
|
|
@@ -171,11 +171,11 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<String> listRemoteFiles(String bucket, String sourcePath) throws Exception {
|
|
|
|
|
|
+ public List<String> listRemoteFiles(String bucket, String sourcePath){
|
|
return listRemoteFiles(bucket, sourcePath, true);
|
|
return listRemoteFiles(bucket, sourcePath, true);
|
|
}
|
|
}
|
|
|
|
|
|
- private List<String> listRemoteFiles(String bucket, String sourcePath, Boolean shutdown) throws Exception {
|
|
|
|
|
|
+ private List<String> listRemoteFiles(String bucket, String sourcePath, Boolean shutdown) {
|
|
List<String> keyList = new ArrayList<>();
|
|
List<String> keyList = new ArrayList<>();
|
|
try {
|
|
try {
|
|
boolean flag = true;
|
|
boolean flag = true;
|
|
@@ -208,11 +208,11 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath) throws Exception {
|
|
|
|
|
|
+ public void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath){
|
|
copyFileBetweenBucket(sourceBucketName, sourcePath, targetBucketName, targetPath, true);
|
|
copyFileBetweenBucket(sourceBucketName, sourcePath, targetBucketName, targetPath, true);
|
|
}
|
|
}
|
|
|
|
|
|
- private void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath, Boolean shutdown) throws Exception {
|
|
|
|
|
|
+ private void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath, Boolean shutdown){
|
|
try {
|
|
try {
|
|
List<String> files = listRemoteFiles(sourceBucketName, sourcePath, false);
|
|
List<String> files = listRemoteFiles(sourceBucketName, sourcePath, false);
|
|
if (ObjectUtils.isEmpty(files)) {
|
|
if (ObjectUtils.isEmpty(files)) {
|
|
@@ -233,7 +233,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void copyFilesBetweenBucket(String sourceBucketName, String targetBucketName, Map<String, String> pathMap) throws Exception {
|
|
|
|
|
|
+ public void copyFilesBetweenBucket(String sourceBucketName, String targetBucketName, Map<String, String> pathMap){
|
|
if (ObjectUtils.isEmpty(pathMap)) {
|
|
if (ObjectUtils.isEmpty(pathMap)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -251,7 +251,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String getFileContent(String bucketName, String remoteFilePath) throws Exception {
|
|
|
|
|
|
+ public String getFileContent(String bucketName, String remoteFilePath){
|
|
try {
|
|
try {
|
|
GetObjectRequest request = new GetObjectRequest(bucketName,remoteFilePath);
|
|
GetObjectRequest request = new GetObjectRequest(bucketName,remoteFilePath);
|
|
S3Object object = s3.getObject(request);
|
|
S3Object object = s3.getObject(request);
|
|
@@ -278,7 +278,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean fileExist(String bucket, String objectName) throws Exception {
|
|
|
|
|
|
+ public boolean fileExist(String bucket, String objectName) {
|
|
try {
|
|
try {
|
|
return s3.doesObjectExist(bucket, objectName);
|
|
return s3.doesObjectExist(bucket, objectName);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -292,7 +292,7 @@ public class S3FileService extends AbstractFYunFileService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void downloadFile(String bucket, String remoteFilePath, String localPath) throws Exception {
|
|
|
|
|
|
+ public void downloadFile(String bucket, String remoteFilePath, String localPath) {
|
|
try {
|
|
try {
|
|
File localFile = new File(localPath);
|
|
File localFile = new File(localPath);
|
|
if (!localFile.getParentFile().exists()) {
|
|
if (!localFile.getParentFile().exists()) {
|