forked from docs/doc-exports
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com> Co-authored-by: Xiong, Chen Xiao <chenxiaoxiong@huawei.com> Co-committed-by: Xiong, Chen Xiao <chenxiaoxiong@huawei.com>
31 lines
1.4 KiB
HTML
31 lines
1.4 KiB
HTML
<a name="dataartsstudio_02_0317"></a><a name="dataartsstudio_02_0317"></a>
|
|
|
|
<h1 class="topictitle1">Parsing a Stream in a Response Message</h1>
|
|
<div id="body8662426"><p id="dataartsstudio_02_0317__en-us_topic_0183389668_p8060118">The response messages of the job export API and connection export API are streams that need to be converted to files. For details, see the following sample code:</p>
|
|
<pre class="screen" id="dataartsstudio_02_0317__en-us_topic_0183389668_screen134017453193">String EXPORT_JOB_URL = "https://{endpoint}/v1/{project_id}/jobs/{job_name}/export";
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
HttpPost httpPost = new HttpPost(EXPORT_JOB_URL);
|
|
httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
|
|
httpPost.setHeader("Accept", "application/octet-stream");
|
|
httpPost.setHeader("X-Auth-Token", token);
|
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|
|
int statusCode = response.getStatusLine().getStatusCode();
|
|
if (statusCode == 200) {
|
|
String filePath = "d:";
|
|
String fileName = "job.zip";
|
|
FileOutputStream fileOutputStream = new FileOutputStream(filePath + fileName);
|
|
response.getEntity().writeTo(fileOutputStream);
|
|
} else {
|
|
System.out.println(statusCode);
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dataartsstudio_02_0309.html">Appendix</a></div>
|
|
</div>
|
|
</div>
|
|
|