From ec7fa1df7b083e7b03ccb8c2dae9a03598f3c00f Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 24 八月 2023 11:18:52 +0800
Subject: [PATCH] 修改MD架构的实体类

---
 src/main/java/com/lf/server/helper/FileHelper.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/FileHelper.java b/src/main/java/com/lf/server/helper/FileHelper.java
index 1f19c9a..132649a 100644
--- a/src/main/java/com/lf/server/helper/FileHelper.java
+++ b/src/main/java/com/lf/server/helper/FileHelper.java
@@ -7,9 +7,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.*;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.StandardCharsets;
@@ -50,7 +48,7 @@
 
         String fileName = file.getName().toLowerCase();
 
-        int idx = fileName.lastIndexOf(StaticData.POINT);
+        int idx = fileName.indexOf(StaticData.POINT);
         if (idx == -1) {
             return "";
         }
@@ -180,6 +178,24 @@
         if (gbNumber < StaticData.D1024) {
             return new DecimalFormat("#.##GB").format(gbNumber);
         }
+        double tbNumber = gbNumber / StaticData.D1024;
+
+        return new DecimalFormat("#.##TB").format(tbNumber);
+    }
+
+    /**
+     * 鑾峰彇鏂囦欢澶у皬
+     */
+    public static String getSizes(double mbNumber) {
+        if (mbNumber < StaticData.D1024) {
+            return new DecimalFormat("#.##MB").format(mbNumber);
+        }
+
+        double gbNumber = mbNumber / StaticData.D1024;
+        if (gbNumber < StaticData.D1024) {
+            return new DecimalFormat("#.##GB").format(gbNumber);
+        }
+
         double tbNumber = gbNumber / StaticData.D1024;
 
         return new DecimalFormat("#.##TB").format(tbNumber);
@@ -386,7 +402,7 @@
     /**
      * 鏍规嵁璺緞鑾峰彇鏂囦欢
      */
-    public static void getFilesByPath(List<File> list, String path) {
+    public static void getFilesByPath(List<String> list, String path) {
         File file = new File(path);
         if (file.isDirectory()) {
             File[] files = file.listFiles();
@@ -398,11 +414,36 @@
                 if (f.isDirectory()) {
                     getFilesByPath(list, f.getPath());
                 } else {
-                    list.add(f);
+                    list.add(f.getPath());
                 }
             }
         } else {
-            list.add(file);
+            list.add(file.getPath());
+        }
+    }
+
+    /**
+     * 澶嶅埗鏂囦欢
+     *
+     * @param src  婧愭枃浠�
+     * @param dest 鐩綍鏂囦欢
+     */
+    public static void copyFile(File src, File dest) throws IOException {
+        InputStream is = null;
+        OutputStream os = null;
+        try {
+            is = new FileInputStream(src);
+            os = new FileOutputStream(dest);
+
+            byte[] buffer = new byte[1024];
+
+            int length;
+            while ((length = is.read(buffer)) > 0) {
+                os.write(buffer, 0, length);
+            }
+        } finally {
+            os.close();
+            is.close();
         }
     }
 }

--
Gitblit v1.9.3