Browse Source

扩展core-fss增加copy方法

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 2 years ago
parent
commit
1a452375a4

+ 8 - 0
core-fss/src/main/java/com/qmth/boot/core/fss/store/FileStore.java

@@ -128,4 +128,12 @@ public interface FileStore {
      * @param path
      */
     boolean delete(String path);
+
+    /**
+     * 将指定路径的文件复制到目标路径中
+     *
+     * @param source
+     * @param target
+     */
+    void copy(String source, String target) throws Exception;
 }

+ 7 - 0
core-fss/src/main/java/com/qmth/boot/core/fss/store/impl/DiskStore.java

@@ -109,4 +109,11 @@ public class DiskStore implements FileStore {
         }
     }
 
+    @Override
+    public void copy(String source, String target) throws Exception {
+        source = formatPath(source);
+        target = formatPath(target);
+        IOUtils.copy(new File(rootDir, source), new File(rootDir, target));
+    }
+
 }

+ 5 - 0
core-fss/src/main/java/com/qmth/boot/core/fss/store/impl/OssStore.java

@@ -104,6 +104,11 @@ public class OssStore implements FileStore {
         return true;
     }
 
+    @Override
+    public void copy(String source, String target) throws Exception {
+        ossClient.copyObject(bucket, formatPath(source), bucket, formatPath(target));
+    }
+
     @Override
     public void close() {
         if (ossClient != null) {