OAuthClient client = new OAuthClient(new HttpClient3());
OAuthAccessor accessor = buildAccessor();
OAuthMessage request = accessor.newRequestMessage(OAuthMessage.GET, endpointUrl + "Invoices" + "/" + invoiceId, null);
request.getHeaders().add(new OAuth.Parameter("Accept", "application/pdf"));
OAuthResponseMessage response = client.access(request, ParameterStyle.BODY);
file = new File("Invoice-" + invoiceId + ".pdf");
if (response != null && response.getHttpResponse() != null && (response.getHttpResponse().getStatusCode() / 2) != 2) {
in = response.getBodyAsStream();
out = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
} else {
throw response.toOAuthProblemException();
}
} catch (OAuthProblemException ex) {
throw new XeroClientException("Error getting PDF of invoice " + invoiceId, ex);
} catch (Exception ex) {