Quellcode durchsuchen

调整模块结构

reghao vor 4 Monaten
Ursprung
Commit
46cf1455f9

+ 12 - 0
jdk/pom.xml

@@ -17,6 +17,18 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>org.hashids</groupId>
+            <artifactId>hashids</artifactId>
+            <version>1.0.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.sejda.imageio</groupId>
+            <artifactId>webp-imageio</artifactId>
+            <version>0.1.6</version>
+        </dependency>
+
         <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>

+ 1 - 1
tool/src/main/java/cn/reghao/jutil/tool/id/IdGenerator.java → jdk/src/main/java/cn/reghao/jutil/jdk/id/IdGenerator.java

@@ -1,4 +1,4 @@
-package cn.reghao.jutil.tool.id;
+package cn.reghao.jutil.jdk.id;
 
 import org.hashids.Hashids;
 

+ 1 - 1
tool/src/main/java/cn/reghao/jutil/tool/id/SnowFlake.java → jdk/src/main/java/cn/reghao/jutil/jdk/id/SnowFlake.java

@@ -1,4 +1,4 @@
-package cn.reghao.jutil.tool.id;
+package cn.reghao.jutil.jdk.id;
 
 /**
  * @author reghao

+ 2 - 2
jdk/src/main/java/cn/reghao/jutil/jdk/file/CaptchaUtil.java → jdk/src/main/java/cn/reghao/jutil/jdk/image/CaptchaUtil.java

@@ -1,4 +1,4 @@
-package cn.reghao.jutil.jdk.file;
+package cn.reghao.jutil.jdk.image;
 
 import javax.imageio.ImageIO;
 import java.awt.*;
@@ -17,7 +17,7 @@ import java.util.Random;
  */
 public class CaptchaUtil {
     // 常用颜色
-    private static final int[][] COLOR = {{0, 135, 255}, {51, 153, 51}, {255, 102, 102}, {255, 153, 0}, {153, 102, 0}, 
+    private static final int[][] COLOR = {{0, 135, 255}, {51, 153, 51}, {255, 102, 102}, {255, 153, 0}, {153, 102, 0},
             {153, 102, 153}, {51, 153, 153}, {102, 102, 255}, {0, 102, 204}, {204, 51, 51}, {0, 153, 204}, {0, 51, 102}};
     private static final Random random = new SecureRandom();
 

+ 19 - 7
tool/src/main/java/cn/reghao/jutil/tool/media/ImageOps.java → jdk/src/main/java/cn/reghao/jutil/jdk/image/ImageUtil.java

@@ -1,6 +1,4 @@
-package cn.reghao.jutil.tool.media;
-
-import net.coobird.thumbnailator.Thumbnails;
+package cn.reghao.jutil.jdk.image;
 
 import javax.imageio.ImageIO;
 import javax.imageio.ImageReader;
@@ -8,7 +6,10 @@ import javax.imageio.stream.ImageInputStream;
 import javax.imageio.stream.ImageOutputStream;
 import java.awt.*;
 import java.awt.image.BufferedImage;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -19,7 +20,7 @@ import java.util.Locale;
  * @author reghao
  * @date 2021-08-04 16:26:13
  */
-public class ImageOps {
+public class ImageUtil {
     public static Size info(File file) throws IOException {
         BufferedImage bi = ImageIO.read(file);
         return new Size(bi.getWidth(), bi.getHeight());
@@ -76,10 +77,21 @@ public class ImageOps {
         ImageIO.write(image, "webp", destFile);
     }
 
-    public static void convert2thumbnail(File srcFile, File destFile, int width, int height) throws IOException {
+    /**
+     * <dependency>
+     *             <groupId>net.coobird</groupId>
+     *             <artifactId>thumbnailator</artifactId>
+     *             <version>0.4.20</version>
+     *         </dependency>
+     *
+     * @param
+     * @return
+     * @date 2025-10-27 09:56:57
+     */
+    /*public static void convert2thumbnail(File srcFile, File destFile, int width, int height) throws IOException {
         BufferedImage image = Thumbnails.of(srcFile).size(width, height).asBufferedImage();
         ImageIO.write(image, "jpeg", destFile);
-    }
+    }*/
 
     public static BufferedImage merge(List<BufferedImage> bufferedImages, boolean isVertical) {
         int size = bufferedImages.size();

+ 0 - 24
tool/pom.xml

@@ -39,29 +39,5 @@
             <artifactId>commons-io</artifactId>
             <version>2.14.0</version>
         </dependency>
-
-        <dependency>
-            <groupId>org.hashids</groupId>
-            <artifactId>hashids</artifactId>
-            <version>1.0.3</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.sejda.imageio</groupId>
-            <artifactId>webp-imageio</artifactId>
-            <version>0.1.6</version>
-        </dependency>
-
-        <dependency>
-            <groupId>net.coobird</groupId>
-            <artifactId>thumbnailator</artifactId>
-            <version>0.4.20</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.google.code.gson</groupId>
-            <artifactId>gson</artifactId>
-            <version>2.10.1</version>
-        </dependency>
     </dependencies>
 </project>

+ 0 - 53
tool/src/main/java/cn/reghao/jutil/tool/json/JdkSerializer.java

@@ -1,53 +0,0 @@
-package cn.reghao.jutil.tool.json;
-
-import java.io.*;
-
-/**
- * JDK 对象序列化器
- *
- * @author reghao
- * @date 2022-05-21 13:49:18
- */
-public class JdkSerializer {
-    public static byte[] serialize(Object object) {
-        if (object == null) {
-            return null;
-        } else {
-            ByteArrayOutputStream stream = new ByteArrayOutputStream();
-
-            try {
-                (new ObjectOutputStream(stream)).writeObject(object);
-            } catch (IOException var3) {
-                throw new IllegalArgumentException("Could not serialize object of type: " + object.getClass(), var3);
-            }
-
-            return stream.toByteArray();
-        }
-    }
-
-    public static Object deserialize(byte[] bytes) {
-        if (bytes == null) {
-            return null;
-        } else {
-            try {
-                return deserialize(new ObjectInputStream(new ByteArrayInputStream(bytes)));
-            } catch (IOException var2) {
-                throw new IllegalArgumentException("Could not deserialize object", var2);
-            }
-        }
-    }
-
-    public static Object deserialize(ObjectInputStream stream) {
-        if (stream == null) {
-            return null;
-        } else {
-            try {
-                return stream.readObject();
-            } catch (IOException var2) {
-                throw new IllegalArgumentException("Could not deserialize object", var2);
-            } catch (ClassNotFoundException var3) {
-                throw new IllegalStateException("Could not deserialize object type", var3);
-            }
-        }
-    }
-}

+ 0 - 38
tool/src/main/java/cn/reghao/jutil/tool/json/JsonArrayDeserializer.java

@@ -1,38 +0,0 @@
-package cn.reghao.jutil.tool.json;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonParser;
-
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * JSON 数组反序列化
- *
- * @author reghao
- * @date 2020-11-11 16:57:04
- */
-public class JsonArrayDeserializer<T> {
-    private final Gson gson = new GsonBuilder()
-            .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter())
-            .create();
-
-    /**
-     * JSON 数组转换为对象集合
-     *
-     * @param
-     * @return
-     * @date 2020-11-11 下午5:14
-     */
-    public List<T> fromJsonArray(String json, Class<T> clazz) {
-        JsonParser parser = new JsonParser();
-        List<T> list = new ArrayList<>();
-        parser.parse(json).getAsJsonArray().forEach(ele -> {
-            list.add(gson.fromJson(ele, clazz));
-        });
-
-        return list;
-    }
-}

+ 0 - 146
tool/src/main/java/cn/reghao/jutil/tool/json/JsonConverter.java

@@ -1,146 +0,0 @@
-package cn.reghao.jutil.tool.json;
-
-import cn.reghao.jutil.jdk.text.TextFile;
-import com.google.gson.*;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
-import com.google.gson.stream.JsonWriter;
-
-import java.io.*;
-import java.lang.reflect.Type;
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * JSON 序列化/反序列化
- *
- * @author reghao
- * @date 2020-11-11 16:57:04
- */
-public class JsonConverter {
-    private static final TypeAdapter<Boolean> booleanAsIntAdapter = new TypeAdapter<>() {
-        @Override public void write(JsonWriter out, Boolean value) throws IOException {
-            if (value == null) {
-                out.nullValue();
-            } else {
-                out.value(value);
-            }
-        }
-        @Override public Boolean read(JsonReader in) throws IOException {
-            JsonToken peek = in.peek();
-            switch (peek) {
-                case BOOLEAN:
-                    return in.nextBoolean();
-                case NULL:
-                    in.nextNull();
-                    return null;
-                case NUMBER:
-                    return in.nextInt() != 0;
-                case STRING:
-                    String intStr = in.nextString();
-                    if (intStr.equalsIgnoreCase("true") || intStr.equalsIgnoreCase("false")) {
-                        return Boolean.parseBoolean(intStr);
-                    } else {
-                        Integer i = Integer.parseInt(intStr);
-                        return i != 0;
-                    }
-                default:
-                    throw new IllegalStateException("Expected BOOLEAN or NUMBER but was " + peek);
-            }
-        }
-    };
-    private static final Gson gson = new GsonBuilder()
-            .disableHtmlEscaping()
-            .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter())
-            .registerTypeAdapter(Boolean.class, booleanAsIntAdapter)
-            .registerTypeAdapter(boolean.class, booleanAsIntAdapter)
-            .create();
-    private static final JsonParser jsonParser = new JsonParser();
-
-    /**
-     * 对象转换为 JSON
-     *
-     * @param
-     * @return
-     * @date 2020-11-11 下午5:10
-     */
-    public static String objectToJson(Object object) {
-        return gson.toJson(object);
-    }
-
-    /**
-     * JSON 转换为对象
-     * TODO <T> 的含义
-     *
-     * @param
-     * @return
-     * @date 2020-11-11 下午5:11
-     */
-    public static <T> T jsonToObject(String json, Class<T> clazz) {
-        return gson.fromJson(json, clazz);
-    }
-
-    /**
-     * 对泛型数据的反序列化
-     *
-     * @param
-     * @return
-     * @date 2021-05-26 下午3:38
-     */
-    public static <T> T jsonToObject(String json, Type type) {
-        return gson.fromJson(json, type);
-    }
-
-    public static <T> T jsonFileToObject(File jsonFile, Type type) {
-        try {
-            JsonReader reader = gson.newJsonReader(new InputStreamReader(new FileInputStream(jsonFile)));
-            return gson.fromJson(reader, type);
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    public static <T> T jsonFileToObject(InputStreamReader streamReader, Type type) {
-        JsonReader reader = gson.newJsonReader(streamReader);
-        return gson.fromJson(reader, type);
-    }
-
-    public static <T> List<T> jsonToObjects(String json, Class<T> clazz) {
-        JsonParser parser = new JsonParser();
-        List<T> list = new ArrayList<>();
-        parser.parse(json).getAsJsonArray().forEach(ele -> {
-            list.add(gson.fromJson(ele, clazz));
-        });
-
-        return list;
-    }
-
-    /**
-     * JSON 文件转换为对象
-     *
-     * @param
-     * @return
-     * @date 2020-11-11 下午5:11
-     */
-    public static JsonElement jsonToJsonElement(File jsonFile) {
-        String content = new TextFile().readFile(jsonFile.getAbsolutePath()).replace(System.lineSeparator(), "");
-        return jsonParser.parse(content);
-    }
-
-    public static JsonElement jsonToJsonElement(String json) {
-        return jsonParser.parse(json);
-    }
-
-    /**
-     * 对象集合转换为 JSON
-     *
-     * @param
-     * @return
-     * @date 2020-11-11 下午5:10
-     */
-    public static <T> String listToJson(List<T> objects) {
-        return gson.toJson(objects);
-    }
-}

+ 0 - 30
tool/src/main/java/cn/reghao/jutil/tool/json/LocalDateTimeAdapter.java

@@ -1,30 +0,0 @@
-package cn.reghao.jutil.tool.json;
-
-import com.google.gson.*;
-
-import java.lang.reflect.Type;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
-/**
- * Gson 序列化/反序列化 Java8 LocalDateTime
- *
- * @author reghao
- * @date 2021-03-04 19:34:31
- */
-public class LocalDateTimeAdapter implements JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> {
-    private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-    private final DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
-
-    @Override
-    public JsonElement serialize(LocalDateTime localDateTime, Type typeOfSrc, JsonSerializationContext context) {
-        return new JsonPrimitive(localDateTime.format(formatter));
-    }
-
-    @Override
-    public LocalDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
-            throws JsonParseException {
-        String timestamp = element.getAsJsonPrimitive().getAsString();
-        return LocalDateTime.parse(timestamp, formatter);
-    }
-}