/** * Create HTTP connection wrapper * * @param url * @param method * @throws HttpRequestException */ public HttpRequest(final URL url, final String method) throws HttpRequestException { try { connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Get reader to response body using given character set. * <p> * This will fall back to using the UTF-8 character set if the given charset * is null * * @param charset * @return reader * @throws HttpRequestException */ public InputStreamReader reader(final String charset) throws HttpRequestException { try { return new InputStreamReader(stream(), getValidCharset(charset)); } catch (UnsupportedEncodingException e) { throw new HttpRequestException(e); } }
/** * Get reader to response body using given character set. * <p> * This will fall back to using the UTF-8 character set if the given charset * is null * * @param charset * @return reader * @throws HttpRequestException */ public InputStreamReader reader(final String charset) throws HttpRequestException { try { return new InputStreamReader(stream(), getValidCharset(charset)); } catch (UnsupportedEncodingException e) { throw new HttpRequestException(e); } }
/** * Write char sequence to request body * <p> * The charset configured via {@link #contentType(String)} will be used and * UTF-8 will be used if it is unset. * * @param value * @return this request * @throws HttpRequestException */ public HttpRequest send(final CharSequence value) throws HttpRequestException { try { openOutput(); output.write(value.toString()); } catch (IOException e) { throw new HttpRequestException(e); } return this; }
/** * Write stream to request body * <p> * The given stream will be closed once sending completes * * @param input * @return this request * @throws HttpRequestException */ public HttpRequest send(final InputStream input) throws HttpRequestException { try { openOutput(); copy(input, output); } catch (IOException e) { throw new HttpRequestException(e); } return this; }
/** * Write contents of file to request body * * @param input * @return this request * @throws HttpRequestException */ public HttpRequest send(final File input) throws HttpRequestException { final InputStream stream; try { stream = new BufferedInputStream(new FileInputStream(input)); incrementTotalSize(input.length()); } catch (FileNotFoundException e) { throw new HttpRequestException(e); } return send(stream); }
/** * Write contents of file to request body * * @param input * @return this request * @throws HttpRequestException */ public HttpRequest send(final File input) throws HttpRequestException { final InputStream stream; try { stream = new BufferedInputStream(new FileInputStream(input)); incrementTotalSize(input.length()); } catch (FileNotFoundException e) { throw new HttpRequestException(e); } return send(stream); }
/** * Create HTTP connection wrapper * * @param url * @param method * @throws HttpRequestException */ public HttpRequest(final CharSequence url, final String method) throws HttpRequestException { try { connection = (HttpURLConnection) new URL(url.toString()).openConnection(); connection.setRequestMethod(method); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Write contents of file to request body * * @param input * @return this request * @throws HttpRequestException */ public HttpRequest send(final File input) throws HttpRequestException { final InputStream stream; try { stream = new BufferedInputStream(new FileInputStream(input)); } catch (FileNotFoundException e) { throw new HttpRequestException(e); } return send(stream); }
/** * Write contents of file to request body * * @param input * @return this request * @throws HttpRequestException */ public HttpRequest send(final File input) throws HttpRequestException { final InputStream stream; try { stream = new BufferedInputStream(new FileInputStream(input)); } catch (FileNotFoundException e) { throw new HttpRequestException(e); } return send(stream); }
/** * Create HTTP connection wrapper * * @param url * @param method * @throws HttpRequestException */ public HttpRequest(final CharSequence url, final String method) throws HttpRequestException { try { connection = (HttpURLConnection) new URL(url.toString()).openConnection(); connection.setRequestMethod(method); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Create HTTP connection wrapper * * @param url * @param method * @throws HttpRequestException */ public HttpRequest(final URL url, final String method) throws HttpRequestException { try { connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Create HTTP connection wrapper * * @param url Remote resource URL. * @param method HTTP request method (e.g., "GET", "POST"). * @throws HttpRequestException */ public HttpRequest(final CharSequence url, final String method) throws HttpRequestException { try { this.url = new URL(url.toString()); } catch (MalformedURLException e) { throw new HttpRequestException(e); } this.requestMethod = method; }
/** * Stream response to given output stream * * @param output * @return this request * @throws HttpRequestException */ public HttpRequest receive(final OutputStream output) throws HttpRequestException { try { return copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Get response as byte array * * @return byte array * @throws HttpRequestException */ public byte[] bytes() throws HttpRequestException { final ByteArrayOutputStream output = byteStream(); try { copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } return output.toByteArray(); }
/** * Stream response to given output stream * * @param output * @return this request * @throws HttpRequestException */ public HttpRequest receive(final OutputStream output) throws HttpRequestException { try { return copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Create HTTP connection wrapper * * @param url Remote resource URL. * @param method HTTP request method (e.g., "GET", "POST"). * @throws HttpRequestException */ public HttpRequest(final CharSequence url, final String method) throws HttpRequestException { try { this.url = new URL(url.toString()); } catch (MalformedURLException e) { throw new HttpRequestException(e); } this.requestMethod = method; }
/** * Stream response to given output stream * * @param output * @return this request * @throws HttpRequestException */ public HttpRequest receive(final OutputStream output) throws HttpRequestException { try { return copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } }
/** * Get response as byte array * * @return byte array * @throws HttpRequestException */ public byte[] bytes() throws HttpRequestException { final ByteArrayOutputStream output = byteStream(); try { copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } return output.toByteArray(); }
/** * Get response as byte array * * @return byte array * @throws HttpRequestException */ public byte[] bytes() throws HttpRequestException { final ByteArrayOutputStream output = byteStream(); try { copy(buffer(), output); } catch (IOException e) { throw new HttpRequestException(e); } return output.toByteArray(); }