Reputation:
I've got this code of my web service:
@GET
@Produces(MediaType.APPLICATION_JSON)
public static Response fillData(final Map<String, Object> data, final String name, @Context final ServletContext context) {
...
final byte[] file = ...
return Response.ok(file).build();
How can I read the response in my client?
final javax.ws.rs.core.Response reponse = client.target(URL_REST).path("/path").request(MediaType.APPLICATION_JSON).get();
This is totally wrong (ByteArray doesn't exist), but I want to do something like it:
byte[] pdfByteArray = reponse.readEntity(ByteArray.class);
How can I do?
Upvotes: 10
Views: 14700
Reputation: 18119
Use java.io.InputStream
InputStream is = reponse.readEntity(InputStream.class);
This allows you to read in a streaming way instead of reading all bytes at once.
Upvotes: 17