一个http请求返回pdf流,但是用下面方法,生成的本地pdf是空白的,该怎么读取这个流然后生成一个pdf文件呢
InputStream content = responseEntity.getContent();
file = new File("E:\\print"+ydbh+".pdf");
FileOutputStream fileOutputStream = new FileOutputStream(file);
int temp;
while ((temp = content.read()) != -1) {
fileOutputStream.write(temp);
}
fileOutputStream.close();
EntityUtils.toString(responseEntity, "UTF-8");返回的是一个下面这样的
%PDF-1.4
%����
3 0 obj
<</Length 62/Filter/FlateDecode>>stream
x�+�r
�26S�00SI�r
�
�2R��*
endstream
endobj
1 0 obj
<</Type/Page/MediaBox[0 0 595 842]/Resources<</Font<</F1 2 0 R>>/ColorSpace<</CS/DeviceRGB>>>>/Tabs/S/Contents 3 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Parent 4 0 R>>
endobj
5 0 obj
[1 0 R/XYZ 0 852 0]
endobj
2 0 obj
<</Type/Font/Subtype/Type1/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>
endobj
4 0 obj
<</Type/Pages/Count 1/Kids[1 0 R]>>
endobj
6 0 obj
<</Names[(JR_PAGE_ANCHOR_0_1) 5 0 R]>>
endobj
7 0 obj
<</Dests 6 0 R>>
endobj
8 0 obj
<</Type/Catalog/Pages 4 0 R/ViewerPreferences<</PrintScaling/AppDefault>>/Names 7 0 R>>
endobj
9 0 obj
<</Producer(iText� 5.5.13 �2000-2018 iText Group NV (AGPL-version))/CreationDate(D:20210820104611+08'00')/ModDate(D:20210820104611+08'00')/Creator(JasperReports Library version 6.0.0)>>
endobj
xref
0 10
0000000000 65535 f
0000000143 00000 n
0000000374 00000 n
0000000015 00000 n
0000000462 00000 n
0000000339 00000 n
0000000513 00000 n
0000000567 00000 n
0000000599 00000 n
0000000702 00000 n
trailer
<</Size 10/Root 8 0 R/Info 9 0 R/ID [<5ba6b8f0b5b4c07d5c3491137a44367f><5ba6b8f0b5b4c07d5c3491137a44367f>]>>
%iText-5.5.13
startxref
905
%%EOF