Skip to content

Instantly share code, notes, and snippets.

@ripper2hl
Created July 16, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripper2hl/7cbd2a7d9576f0912e74 to your computer and use it in GitHub Desktop.
Save ripper2hl/7cbd2a7d9576f0912e74 to your computer and use it in GitHub Desktop.
Obtiene un archivo mediante una api rest por post y lo convierte a un arreglo de bytes de java
public void getFile(Url){
try {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request(MediaType.WILDCARD).post(Entity.entity("data=123", MediaType.APPLICATION_FORM_URLENCODED_TYPE));
InputStream input = response.readEntity(InputStream.class);
byte[] byteArray = IOUtils.toByteArray(input);
FileOutputStream fos = new FileOutputStream(new File("/tmp/1.pdf"));
fos.write(byteArray);
fos.flush();
fos.close();
response.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment