代码如下:
package com.x3.gls.util; import com.x3.base.core.exception.BusinessException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.Base64; /** * 图片远程下载 */ @Component public class RemoteImageUtil { /** * 日志 */ private static final Logger log = LoggerFactory.getLogger(HttpPostUtil.class); /** * 图片远程下载并转换为Base64 * * @param imageUrl * @return */ public static String convertImageUrlToBase64(String imageUrl) { RestTemplate restTemplate = new RestTemplate(); try { ResponseEntity<byte[]> responseEntity = restTemplate.getForEntity(imageUrl, byte[].class); byte[] imageBytes = responseEntity.getBody(); if (imageBytes != null) { return Base64.getEncoder().encodeToString(imageBytes); } else { return null; } } catch (Exception e) { log.debug("RemoteImageUtil-convertImageUrlToBase64-01-异常响应数据:{}", e.getMessage()); throw new BusinessException("RemoteImageUtil-convertImageUrlToBase64-02", "下载文件[" + imageUrl + "]出错:" + e.getMessage(), imageUrl); } } }
public class test { public static void main(String[] args) { &...
Java5 引入了一种主要用于数组的增强型 for 循环,类似js中的for inpublic class Member { public static void main(String[]&...
java判断字符是否是一个字母System.out.println(Character.isLetter('a'));java判断字符是否是一个数字System.out.println(Character.isDigit('0'));java判断字符是否是一个空白Sy...
在java中字符串属于对象,刚开始我就疑惑为什么int char等类型都是小写,结果String是大写,java太反人类,后来才知道String是对象。(1).java创建字符串String text = "net"; String tex...
(1).创建数组double[] myList = new double[size]; //推荐创建方式 double myList[] = new double[size];  ...
pattern表示正则表达式,接收正则表达式作为参数例子:String content = "my name is gaojiufeng"; String pattern = "....