|
@@ -7,10 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.URL;
|
|
|
-import java.net.URLDecoder;
|
|
|
+import java.net.*;
|
|
|
import java.util.*;
|
|
|
|
|
|
import org.apache.tools.zip.ZipEntry;
|
|
@@ -23,6 +20,7 @@ import org.bytedeco.javacv.Java2DFrameConverter;
|
|
|
import org.bytedeco.javacv.OpenCVFrameConverter;
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
import sun.misc.BASE64Decoder;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
@@ -413,6 +411,22 @@ public class FileUtils {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public static String getBase64ContentFromUrl(String urlStr) throws IOException {
|
|
|
+ URL url = new URL(urlStr);
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
+ // 设置超时间为3秒
|
|
|
+ conn.setConnectTimeout(3 * 1000);
|
|
|
+ // 防止屏蔽程序抓取而返回403错误
|
|
|
+ conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
|
|
+
|
|
|
+ // 得到输入流
|
|
|
+ InputStream inputStream = conn.getInputStream();
|
|
|
+ // 获取自己数组
|
|
|
+ byte[] data = readInputStream(inputStream);
|
|
|
+
|
|
|
+ return new BASE64Encoder().encode(data);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 从输入流中获取字节数组
|
|
|
*
|