From 25ddef3bbf39fa5dfdb5289f6f2798786a10d360 Mon Sep 17 00:00:00 2001 From: maxf <1107047387@qq.com> Date: Fri, 28 Dec 2018 20:15:10 +0800 Subject: [PATCH] =?UTF-8?q?1.2.8=20=E6=96=B0=E5=A2=9EObjUtil=20=E5=AF=B9?= =?UTF-8?q?=E7=B1=BB=EF=BC=88=E5=AF=B9=E8=B1=A1=EF=BC=89=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=8F=90=E4=BE=9B=E6=B7=B1=E5=BA=A6?= =?UTF-8?q?=E5=85=8B=E9=9A=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- UPDATE.md | 14 +++ WIKI.md | 7 ++ pom.xml | 2 +- .../java/com/yexuejc/base/util/ObjUtil.java | 101 ++++++++++++++++++ 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/yexuejc/base/util/ObjUtil.java diff --git a/README.md b/README.md index 045fdf4..db6ecaa 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ ### 使用 ->yexuejc.base.version=1.2.6 +>yexuejc.base.version=1.2.8 pom.xml ``` diff --git a/UPDATE.md b/UPDATE.md index 1b254dc..aff1f9f 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,6 +1,20 @@ yexuejc-base 更新记录 ------------------ +#### version :1.2.8 +**time:2018-12-28 20:10:14**
+**branch:** master
+**update:**
+>1. 新增[ObjUtil](src/main/java/com/yexuejc/base/util/ObjUtil.java) 对类(对象)进行处理,提供深度克隆 + +# +#### version :1.2.6 +**time:2018-12-21 14:58:49**
+**branch:** master
+**update:**
+>1. RSA 验签增加初始化方法 + +# #### version :1.2.7 **time:2018-12-24 15:31:01**
**branch:** master
diff --git a/WIKI.md b/WIKI.md index 598c021..2278248 100644 --- a/WIKI.md +++ b/WIKI.md @@ -24,5 +24,12 @@ yexuejc-base 文档 ##### 17. RegexUtils 常用正则 ##### 18. StrUtil 字符串工具 ##### 19. SysUtils 常用java系统操作封装 +##### 20. ObjUtil 对象的操作(深度克隆) + +> com.yexuejc.base.encrypt 加密相关 +##### 21. RSA 加密 +##### 22. RSA2 RSA加密获取文件密钥 +##### 23. RSACoder RSA工具 +##### 24. SignAlgorithm 签名算法类型 待完善...... \ No newline at end of file diff --git a/pom.xml b/pom.xml index 00a2e9d..791015d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.yexuejc.base yexuejc-base - 1.2.7 + 1.2.8 ${project.artifactId} diff --git a/src/main/java/com/yexuejc/base/util/ObjUtil.java b/src/main/java/com/yexuejc/base/util/ObjUtil.java new file mode 100644 index 0000000..172568a --- /dev/null +++ b/src/main/java/com/yexuejc/base/util/ObjUtil.java @@ -0,0 +1,101 @@ +package com.yexuejc.base.util; + +import com.fasterxml.jackson.databind.util.BeanUtil; +import com.sun.org.apache.xml.internal.serializer.OutputPropertyUtils; + +import java.io.*; + +/** + * 对象工具:对类的操作 + * + * @author maxf + * @version 1.0 + * @ClassName ObjUtil + * @Description + * @date 2018/12/28 15:54 + */ +public class ObjUtil { + private ObjUtil() { + } + + /** + *

深度克隆对象

+ *

+ * 将该对象序列化成流,因为写在流里的是对象的一个拷贝,而原对象仍然存在于JVM里面。所以利用这个特性可以实现对象的深拷贝 + *

+ * 注:克隆对象必须序列化 + * + * @param t + * @param + * @return + */ + public static T depthClone(T t) { + T outer = null; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(t); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + outer = (T) ois.readObject(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return outer; + } + +// public static void main(String[] args) { +//// test1(); +//// test2(); +// +// } +// +// private static void test2() { +// B t = new B(); +// t.sex = "男"; +// t.age = 18; +// A test = new A(); +// test.name = "张三"; +// t.test = test; +// B b = depthClone(t); +// System.out.println(JsonUtil.obj2Json(b)); +// } +// +// static class A implements Serializable { +// private static final long serialVersionUID = -8462118058721865488L; +// public String name; +// } +// +// static class B implements Serializable { +// private static final long serialVersionUID = 3297717505428005316L; +// public int age; +// public String sex; +// public A test; +// } +// +// static class C implements Serializable { +// private static final long serialVersionUID = 3297717505428005316L; +// public int age; +// public String sex; +// public A test; +// } +// +// private static void test1() { +// ApiVO apiVO = new ApiVO(ApiVO.STATUS.S); +// apiVO.setMsg("asdsadsad"); +// apiVO.setObject1("sadsadsad"); +// +// Resps obj = new Resps<>(); +// obj.setSucc("安达圣斗士", "ok"); +// System.out.println(obj); +// apiVO.setObject2(obj); +// ApiVO apiVO1 = depthClone(apiVO); +// System.out.println(apiVO == apiVO1); +// System.out.println(JsonUtil.obj2Json(apiVO1)); +// System.out.println(JsonUtil.obj2Json(apiVO1.getObject1(String.class))); +// System.out.println(JsonUtil.obj2Json(apiVO1.getObject2(Resps.class))); +// System.out.println(apiVO1.getObject2(Resps.class) == obj); +// } +}