java保存api返回的pdf流文件
发布时间:2022-10-20 11:51:19 435 相关标签:
- 方法一
ResponseEntity resource = restTemplate.postForEntity(reUrl, requestEntity , Resource.class);
InputStream inputStream = resource.getBody().getInputStream();
byte[] label = this.input2byte(inputStream);
String labelStr = Base64.getEncoder().encodeToString(label);
- 方法二
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;
}
文章来源: https://blog.51cto.com/wms3001/5768502
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报