From d1f26741bddf6f512d62c0100d42c52be8d37e76 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 06 二月 2021 15:35:40 +0800
Subject: [PATCH] 工具类优化

---
 utils/src/main/java/org/yeshi/utils/FileUtil.java |  264 ++++++++++++++++++++++++++--------------------------
 1 files changed, 132 insertions(+), 132 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/FileUtil.java b/utils/src/main/java/org/yeshi/utils/FileUtil.java
index ee7be67..873b009 100644
--- a/utils/src/main/java/org/yeshi/utils/FileUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/FileUtil.java
@@ -1,132 +1,132 @@
-package org.yeshi.utils;
-
-import java.io.*;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.IOUtils;
-
-public class FileUtil {
-
-    @SuppressWarnings("deprecation")
-    public static String getRealPath(HttpServletRequest request, String folderName) {
-        String f = request.getRealPath(folderName);
-        if (!new File(f).exists())
-            new File(f).mkdirs();
-        return f;
-    }
-
-    public static String getFileMD5(File file) throws IOException {
-        FileInputStream fis = new FileInputStream(file);
-        String md5 = DigestUtils.md5Hex(IOUtils.toByteArray(fis));
-        IOUtils.closeQuietly(fis);
-        return md5;
-    }
-
-    public static void deleteFileDir(File path) {
-        if (!path.exists())
-            return;
-        if (path.isFile()) {
-            path.delete();
-            return;
-        }
-        File[] files = path.listFiles();
-        for (int i = 0; i < files.length; i++) {
-            deleteFileDir(files[i]);
-        }
-        path.delete();
-    }
-
-    /**
-     * 灏嗚緭鍏ユ祦瀛樹负鏈湴鏂囦欢
-     *
-     * @param inputStream
-     * @param path
-     * @return
-     * @throws IOException
-     */
-    public static String saveAsFile(InputStream inputStream, String path) throws IOException {
-        if (!new File(path).exists()) {
-            new File(path).createNewFile();
-        }
-
-        FileOutputStream fileOut = new FileOutputStream(new File(path));
-        byte[] buf = new byte[1024 * 8];
-        while (true) {
-            int read = 0;
-            if (inputStream != null) {
-                read = inputStream.read(buf);
-            }
-            if (read == -1) {
-                break;
-            }
-            fileOut.write(buf, 0, read);
-        }
-        fileOut.close();
-        return path;
-    }
-
-    /**
-     * 鑾峰彇缂撳瓨鏂囦欢澶圭洰褰�
-     *
-     * @return
-     */
-    public static String getCacheDir() {
-        String os = System.getProperty("os.name");
-        if (os.toLowerCase().startsWith("win")) {
-            File f = new File("D:/cache");
-            if (!f.exists())
-                f.mkdirs();
-            return f.getPath();
-        } else {
-            File f = new File("/usr/local/cache");
-            if (!f.exists())
-                f.mkdirs();
-            return f.getPath();
-        }
-    }
-
-
-    /**
-     * 灏嗚緭鍏ユ祦瀛樹负鏈湴鏂囦欢
-     *
-     * @param inputStream
-     * @param path
-     * @return
-     * @throws IOException
-     */
-    public static String saveAsFileByte(byte[] b, String path) throws IOException {
-        if (!new File(path).exists()) {
-            new File(path).createNewFile();
-        }
-
-        FileOutputStream fileOut = new FileOutputStream(path);
-        fileOut.write(b);
-        fileOut.flush();
-        fileOut.close();
-        return path;
-    }
-
-
-    /**
-     * 澶嶅埗inputStream
-     * @param input
-     * @return
-     */
-    public static ByteArrayOutputStream cloneInputStream(InputStream input) {
-        try {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            byte[] buffer = new byte[1024];
-            int len;
-            while ((len = input.read(buffer)) > -1) {
-                baos.write(buffer, 0, len);
-            }
-            baos.flush();
-            return baos;
-        } catch (IOException e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-}
+package org.yeshi.utils;
+
+import java.io.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.IOUtils;
+
+public class FileUtil {
+
+    @SuppressWarnings("deprecation")
+    public static String getRealPath(HttpServletRequest request, String folderName) {
+        String f = request.getRealPath(folderName);
+        if (!new File(f).exists())
+            new File(f).mkdirs();
+        return f;
+    }
+
+    public static String getFileMD5(File file) throws IOException {
+        FileInputStream fis = new FileInputStream(file);
+        String md5 = DigestUtils.md5Hex(IOUtils.toByteArray(fis));
+        IOUtils.closeQuietly(fis);
+        return md5;
+    }
+
+    public static void deleteFileDir(File path) {
+        if (!path.exists())
+            return;
+        if (path.isFile()) {
+            path.delete();
+            return;
+        }
+        File[] files = path.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            deleteFileDir(files[i]);
+        }
+        path.delete();
+    }
+
+    /**
+     * 灏嗚緭鍏ユ祦瀛樹负鏈湴鏂囦欢
+     *
+     * @param inputStream
+     * @param path
+     * @return
+     * @throws IOException
+     */
+    public static String saveAsFile(InputStream inputStream, String path) throws IOException {
+        if (!new File(path).exists()) {
+            new File(path).createNewFile();
+        }
+
+        FileOutputStream fileOut = new FileOutputStream(new File(path));
+        byte[] buf = new byte[1024 * 8];
+        while (true) {
+            int read = 0;
+            if (inputStream != null) {
+                read = inputStream.read(buf);
+            }
+            if (read == -1) {
+                break;
+            }
+            fileOut.write(buf, 0, read);
+        }
+        fileOut.close();
+        return path;
+    }
+
+    /**
+     * 鑾峰彇缂撳瓨鏂囦欢澶圭洰褰�
+     *
+     * @return
+     */
+    public static String getCacheDir() {
+        String os = System.getProperty("os.name");
+        if (os.toLowerCase().startsWith("win")) {
+            File f = new File("D:/cache");
+            if (!f.exists())
+                f.mkdirs();
+            return f.getPath();
+        } else {
+            File f = new File("/usr/local/cache");
+            if (!f.exists())
+                f.mkdirs();
+            return f.getPath();
+        }
+    }
+
+
+    /**
+     * 灏嗚緭鍏ユ祦瀛樹负鏈湴鏂囦欢
+     *
+     * @param inputStream
+     * @param path
+     * @return
+     * @throws IOException
+     */
+    public static String saveAsFileByte(byte[] b, String path) throws IOException {
+        if (!new File(path).exists()) {
+            new File(path).createNewFile();
+        }
+
+        FileOutputStream fileOut = new FileOutputStream(path);
+        fileOut.write(b);
+        fileOut.flush();
+        fileOut.close();
+        return path;
+    }
+
+
+    /**
+     * 澶嶅埗inputStream
+     * @param input
+     * @return
+     */
+    public static ByteArrayOutputStream cloneInputStream(InputStream input) {
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int len;
+            while ((len = input.read(buffer)) > -1) {
+                baos.write(buffer, 0, len);
+            }
+            baos.flush();
+            return baos;
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+}

--
Gitblit v1.8.0