浏览代码

优化代码

tianboguang 3 年之前
父节点
当前提交
63a6804036

+ 11 - 15
4dkankan-utils-fyun-local/src/main/java/com/fdkankan/fyun/local/LocalFileService.java

@@ -18,29 +18,25 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 @Component
-@ConditionalOnProperty(name = "fyun.type",havingValue = "local")
+@ConditionalOnProperty(name = "fyun.type", havingValue = "local")
 public class LocalFileService extends AbstractFYunFileService {
 
     private Logger log = LoggerFactory.getLogger(this.getClass().getName());
 
     @Override
     public String uploadFile(String bucket, byte[] data, String remoteFilePath) {
-        FileUtil.writeBytes(data, getOssPath(bucket,remoteFilePath));
+        FileUtil.writeBytes(data, getOssPath(bucket, remoteFilePath));
         return null;
     }
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath) {
-        return uploadFile(bucket, filePath, remoteFilePath, true, null);
+        return uploadFile(bucket, filePath, remoteFilePath, null);
     }
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
-        return uploadFile(bucket, filePath, remoteFilePath, true, headers);
-    }
-
-    private String uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers) {
-        FileUtil.copy(filePath, getOssPath(bucket,remoteFilePath),true);
+        FileUtil.copy(filePath, getOssPath(bucket, remoteFilePath), true);
         return null;
     }
 
@@ -73,19 +69,19 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public void deleteFile(String bucket, String remoteFilePath) throws IOException {
-        FileUtil.del(getOssPath(bucket,remoteFilePath));
+        FileUtil.del(getOssPath(bucket, remoteFilePath));
     }
 
     @Override
     public void deleteFolder(String bucket, String remoteFolderPath) {
-        FileUtil.del(getOssPath(bucket,remoteFolderPath));
+        FileUtil.del(getOssPath(bucket, remoteFolderPath));
     }
 
     @Override
     public void uploadMulFiles(String bucket, Map<String, String> filepaths) {
         try {
             for (Map.Entry<String, String> entry : filepaths.entrySet()) {
-                uploadFile(bucket, entry.getKey(), entry.getValue(), false,null);
+                uploadFile(bucket, entry.getKey(), entry.getValue(), null);
             }
         } catch (Exception e) {
             log.error("OSS批量上传文件失败!");
@@ -99,8 +95,8 @@ public class LocalFileService extends AbstractFYunFileService {
     }
 
     private List<String> listRemoteFiles(String bucket, String sourcePath, Boolean shutdown) {
-        return FileUtil.loopFiles(getOssPath(bucket,sourcePath)).stream()
-                .map(f->f.getAbsolutePath().replace(LocalConstants.BASE_PATH.concat(bucket).concat(File.separator),""))
+        return FileUtil.loopFiles(getOssPath(bucket, sourcePath)).stream()
+                .map(f -> f.getAbsolutePath().replace(LocalConstants.BASE_PATH.concat(bucket).concat(File.separator), ""))
                 .collect(Collectors.toList());
     }
 
@@ -129,12 +125,12 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public String getFileContent(String bucketName, String remoteFilePath) {
-       return FileUtil.readUtf8String(getOssPath(bucketName,remoteFilePath));
+        return FileUtil.readUtf8String(getOssPath(bucketName, remoteFilePath));
     }
 
     @Override
     public boolean fileExist(String bucket, String objectName) {
-        return FileUtil.exist(getOssPath(bucket,objectName));
+        return FileUtil.exist(getOssPath(bucket, objectName));
     }
 
     @Override

+ 5 - 9
4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/OssFileService.java

@@ -20,7 +20,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 @Component
-@ConditionalOnProperty(name = "fyun.type",havingValue = "oss")
+@ConditionalOnProperty(name = "fyun.type", havingValue = "oss")
 public class OssFileService extends AbstractFYunFileService {
 
     private Logger log = LoggerFactory.getLogger(this.getClass().getName());
@@ -41,15 +41,11 @@ public class OssFileService extends AbstractFYunFileService {
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath) {
-        return uploadFile(bucket, filePath, remoteFilePath, true, null);
+        return uploadFile(bucket, filePath, remoteFilePath, null);
     }
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
-        return uploadFile(bucket, filePath, remoteFilePath, true, headers);
-    }
-
-    private String uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers) {
         try {
             File file = new File(filePath);
             if (!file.exists()) {
@@ -66,9 +62,9 @@ public class OssFileService extends AbstractFYunFileService {
             if (filePath.contains(".mp3")) {
                 metadata.setContentType("audio/mp3");
             }
-            if(org.apache.commons.lang3.ObjectUtils.isNotEmpty(headers)){
+            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(headers)) {
                 for (Map.Entry<String, String> header : headers.entrySet()) {
-                    metadata.setHeader(header.getKey(),header.getValue());
+                    metadata.setHeader(header.getKey(), header.getValue());
                 }
             }
             ossClient.putObject(bucket, remoteFilePath, new File(filePath), metadata);
@@ -136,7 +132,7 @@ public class OssFileService extends AbstractFYunFileService {
     public void uploadMulFiles(String bucket, Map<String, String> filepaths) {
         try {
             for (Map.Entry<String, String> entry : filepaths.entrySet()) {
-                uploadFile(bucket, entry.getKey(), entry.getValue(), false,null);
+                uploadFile(bucket, entry.getKey(), entry.getValue(), null);
             }
         } catch (Exception e) {
             log.error("OSS批量上传文件失败!");

+ 3 - 7
4dkankan-utils-fyun-s3/src/main/java/com/fdkankan/fyun/s3/S3FileService.java

@@ -44,15 +44,11 @@ public class S3FileService extends AbstractFYunFileService {
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath){
-        return uploadFile(bucket, filePath, remoteFilePath,true,null);
+        return uploadFile(bucket, filePath, remoteFilePath,null);
     }
 
     @Override
-    public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers){
-        return uploadFile(bucket, filePath, remoteFilePath,true,headers);
-    }
-
-    private String uploadFile(String bucket, String filePath, String remoteFilePath, Boolean shutdown,Map<String, String> headers){
+    public String uploadFile(String bucket, String filePath, String remoteFilePath,Map<String, String> headers){
         try {
             File file = new File(filePath);
             if (!file.exists()) {
@@ -162,7 +158,7 @@ public class S3FileService extends AbstractFYunFileService {
     public void uploadMulFiles(String bucket, Map<String, String> filepaths){
         try {
             for (Map.Entry<String, String> entry : filepaths.entrySet()) {
-                uploadFile(bucket, entry.getKey(), entry.getValue(), false,null);
+                uploadFile(bucket, entry.getKey(), entry.getValue(),null);
             }
         } catch (Exception e) {
             log.error("OSS批量上传文件失败!");