I Am new to jersey/JAX-RS implementation. Please find below my jersey client code to download file:
Client client = Client.create();
WebResource wr = clien
Here's another way of doing it using Files.copy().
private long downloadReport(String url){
long bytesCopied = 0;
Path out = Paths.get(this.fileInfo.getLocalPath());
try {
WebTarget webTarget = restClient.getClient().target(url);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.TEXT_PLAIN_TYPE);
Response response = invocationBuilder.get();
if (response.getStatus() != 200) {
System.out.println("HTTP status " response.getStatus());
return bytesCopied;
}
InputStream in = response.readEntity( InputStream.class );
bytesCopied = Files.copy(in, out, REPLACE_EXISTING);
in.close();
} catch( IOException e ){
System.out.println(e.getMessage());
}
return bytesCopied;
}