mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-11-19 07:17:42 +08:00
Compare commits
7 Commits
1.4.4
...
8741562463
| Author | SHA1 | Date | |
|---|---|---|---|
| 8741562463 | |||
| b97fdf65bc | |||
| 3987f982be | |||
| 556f2a49d2 | |||
| 3b0cdc832b | |||
| 75f7aaeb77 | |||
| a7132e9b5b |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -22,4 +22,5 @@ build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
.nb-gradle/
|
||||
*.iml~
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
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;
|
||||
|
||||
@@ -286,7 +285,17 @@ public class FileUtil {
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String base64(File file) {
|
||||
public static String base64ToStr(File file) {
|
||||
return new String(base64(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件base64
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static byte[] base64(File file) {
|
||||
FileInputStream fileInputStream = null;
|
||||
byte[] data = null;
|
||||
// 读取图片字节数组
|
||||
@@ -300,8 +309,22 @@ public class FileUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
@@ -11,6 +9,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.Base64;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
@@ -47,8 +46,7 @@ public class ImgUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 对字节数组Base64编码
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
return encoder.encode(data.toByteArray());
|
||||
return new String(Base64.getEncoder().encode(data.toByteArray()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +235,7 @@ public class ImgUtil {
|
||||
* @return String 编码后的字符串
|
||||
*/
|
||||
public static String encode(byte[] bytes) {
|
||||
return new BASE64Encoder().encode(bytes);
|
||||
return new String(Base64.getEncoder().encode(bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,10 +246,7 @@ public class ImgUtil {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] decode(String encodeStr) throws IOException {
|
||||
byte[] bt = null;
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
bt = decoder.decodeBuffer(encodeStr);
|
||||
return bt;
|
||||
return Base64.getDecoder().decode(encodeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user