/** * Downloads attachment to byte array * * @return a byte[] * * @throws JiraException when the download fails */ public byte[] download() throws JiraException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); try{ HttpGet get = new HttpGet(content); HttpResponse response = restclient.getHttpClient().execute(get); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); int next = inputStream.read(); while (next > -1) { bos.write(next); next = inputStream.read(); } bos.flush(); } }catch(IOException e){ throw new JiraException(String.format("Failed downloading attachment from %s: %s", this.content, e.getMessage())); } return bos.toByteArray(); }
/** * Downloads attachment to byte array * * @return a byte[] * * @throws JiraException when the download fails */ public byte[] download() throws JiraException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); try{ HttpGet get = new HttpGet(content); HttpResponse response = restclient.getHttpClient().execute(get); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); int next = inputStream.read(); while (next > -1) { bos.write(next); next = inputStream.read(); } bos.flush(); } }catch(IOException e){ throw new JiraException(String.format("Failed downloading attachment from %s: %s", this.content, e.getMessage())); } return bos.toByteArray(); }
public JiraContext(String url, String username, String password) { this.credentials = new BasicCredentials(username, password); this.jiraClient = new JiraClient(url, credentials); final HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 10000); ((DefaultHttpClient)getJiraClient().getRestClient().getHttpClient()).setParams(httpParams); }