mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-08-05 18:29:31 +08:00
Compare commits
No commits in common. "6ff859b4fb38981ad60f03483fe5741418fbe26d" and "3b0cdc832b4dcd9ce01dee81921070526e72d83b" have entirely different histories.
6ff859b4fb
...
3b0cdc832b
@ -23,7 +23,7 @@ gitee:https://gitee.com/jzsw-it/yexuejc-base
|
||||
|
||||
|
||||
### 使用
|
||||
>yexuejc.base.version=1.4.5
|
||||
>yexuejc.base.version=1.4.1
|
||||
|
||||
pom.xml
|
||||
```
|
||||
|
@ -1,12 +1,6 @@
|
||||
yexuejc-base 更新记录
|
||||
------------------
|
||||
|
||||
#### version :1.4.5
|
||||
**time:2022-5-9 13:37:31** <br/>
|
||||
**branch:** master <br/>
|
||||
**update:** <br/>
|
||||
>1. 扩展FileUtil,优化Base64的包
|
||||
#
|
||||
#### version :1.4.4
|
||||
**time:2021-4-24 00:41:31** <br/>
|
||||
**branch:** master <br/>
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>top.yexuejc</groupId>
|
||||
<artifactId>yexuejc-base</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>1.4.4</version>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<url>https://github.com/yexuejc/yexuejc-base</url>
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
@ -285,17 +286,7 @@ public class FileUtil {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String base64ToStr(File file) {
|
||||
return new String(base64(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件base64
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static byte[] base64(File file) {
|
||||
public static String base64(File file) {
|
||||
FileInputStream fileInputStream = null;
|
||||
byte[] data = null;
|
||||
// 读取图片字节数组
|
||||
@ -309,22 +300,8 @@ public class FileUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
return Base64.getEncoder().encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* base64转文件
|
||||
* <p>
|
||||
* <i>
|
||||
* 文件转base64请使用 {@link FileUtil#base64(File)}
|
||||
* </i>
|
||||
*
|
||||
* @param decode {@link FileUtil#base64ToStr(File)} 的结果
|
||||
* @param fileName 文件名称(包含路径)
|
||||
* @return 返回保存地址
|
||||
*/
|
||||
public static String base64ToFile(String decode, String fileName) {
|
||||
return base64ToFile(Base64.getDecoder().decode(decode.getBytes()), fileName);
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
@ -9,7 +11,6 @@ import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.Base64;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
@ -46,7 +47,8 @@ public class ImgUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
return new String(Base64.getEncoder().encode(data.toByteArray()));
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +237,7 @@ public class ImgUtil {
|
||||
* @return String 编码后的字符串
|
||||
*/
|
||||
public static String encode(byte[] bytes) {
|
||||
return new String(Base64.getEncoder().encode(bytes));
|
||||
return new BASE64Encoder().encode(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +248,10 @@ public class ImgUtil {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] decode(String encodeStr) throws IOException {
|
||||
return Base64.getDecoder().decode(encodeStr);
|
||||
byte[] bt = null;
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
bt = decoder.decodeBuffer(encodeStr);
|
||||
return bt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,36 +0,0 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonUtilTest {
|
||||
public static void main(String[] args) {
|
||||
TestA testA = new TestA("张三", 1, false);
|
||||
System.out.println(JsonUtil.json2Obj(JsonUtil.obj2Json(testA), Map.class));
|
||||
|
||||
List<TestA> list = new ArrayList<>();
|
||||
list.add(testA);
|
||||
list.add(testA);
|
||||
list.add(testA);
|
||||
System.out.println(JsonUtil.json2Obj(JsonUtil.obj2Json(list), List.class,TestA.class));
|
||||
}
|
||||
|
||||
static class TestA implements Serializable {
|
||||
public String name;
|
||||
public Integer id;
|
||||
public Boolean sex;
|
||||
|
||||
public TestA() {
|
||||
}
|
||||
|
||||
public TestA(String name, Integer id, Boolean sex) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.sex = sex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user