返回

java保存api返回的pdf流文件

发布时间:2022-10-20 11:51:19 435
  1. 方法一
ResponseEntity resource = restTemplate.postForEntity(reUrl, requestEntity , Resource.class);
InputStream inputStream = resource.getBody().getInputStream();
byte[] label = this.input2byte(inputStream);
String labelStr = Base64.getEncoder().encodeToString(label);
  1. 方法二
 HttpResponse response = Unirest.get(reUrl)
.basicAuth(order.getCompany().getAppUser(),order.getCompany().getAppPass())
.asBinary();
byte[] label = this.input2byte(response.getBody());
//System.out.println(res);
// byte[] label = res.getBytes(StandardCharsets.UTF_8);
String labelStr = Base64.getEncoder().encodeToString(label);

public byte[] input2byte(InputStream inStream) throws IOException {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in2b = swapStream.toByteArray();
return in2b;
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线