/** * Fetches response content from server as String. * * @return response content from server as String. */ public String text() { try { connect(); return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream()); } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } }
protected T connect() { if (!connected) { T t = doConnect(); connected = true; return t; } else { return (T) this; } }
/** * Fetches response content from server as bytes. * * @return response content from server as bytes. */ public byte[] bytes() { connect(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int count; try { InputStream in = connection.getInputStream(); while ((count = in.read(bytes)) != -1) { bout.write(bytes, 0, count); } } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } return bout.toByteArray(); }
/** * Returns HTTP headers as sent by server. * * @return HTTP headers as sent by server. */ public Map<String, List<String>> headers() { connect(); return connection.getHeaderFields(); }
/** * Fetches response content from server as bytes. * * @return response content from server as bytes. */ public byte[] bytes() { connect(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int count; try { InputStream in = connection.getInputStream(); while ((count = in.read(bytes)) != -1) { bout.write(bytes, 0, count); } } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } dispose(); return bout.toByteArray(); }
/** * Returns HTTP response code. * * @return HTTP response code. */ public int responseCode() { try { connect(); return connection.getResponseCode(); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }
/** * Fetches response content from server as String. * * @param encoding - name of supported charset to apply when reading data. * * @return response content from server as String. */ public String text(String encoding) { try { connect(); return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding); } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } }
/** * Fetches response content from server as bytes. * * @return response content from server as bytes. */ public byte[] bytes() { connect(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int count; try { InputStream in = connection.getInputStream(); while ((count = in.read(bytes)) != -1) { bout.write(bytes, 0, count); } } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } return bout.toByteArray(); }
/** * Returns response message from server, such as "OK", or "Created", etc. * * @return response message from server, such as "OK", or "Created", etc. */ public String responseMessage() { try { connect(); return connection.getResponseMessage(); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }
protected T connect() { if (!connected) { T t = doConnect(); connected = true; return t; } else { return (T) this; } }
/** * Fetches response content from server as String. * * @return response content from server as String. */ public String text() { try { connect(); String result = responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream()); dispose(); return result; } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); } }
/** * Returns HTTP headers as sent by server. * * @return HTTP headers as sent by server. */ public Map<String, List<String>> headers() { connect(); return connection.getHeaderFields(); }
protected T connect() { if (!connected) { T t = doConnect(); connected = true; return t; } else { return (T) this; } }
/** * Fetches response content from server as String. * * @return response content from server as String. */ public String text() { try { connect(); return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream()); } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } }
/** * Returns HTTP headers as sent by server. * * @return HTTP headers as sent by server. */ public Map<String, List<String>> headers() { connect(); return connection.getHeaderFields(); }
/** * Fetches response content from server as String. * * @param encoding - name of supported charset to apply when reading data. * * @return response content from server as String. */ public String text(String encoding) { try { connect(); return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding); } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); }finally { dispose(); } }
/** * Returns HTTP response code. * * @return HTTP response code. */ public int responseCode() { try { connect(); return connection.getResponseCode(); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }
/** * Fetches response content from server as String. * * @param encoding - name of supported charset to apply when reading data. * * @return response content from server as String. */ public String text(String encoding) { try { connect(); String result = responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding); dispose(); return result; } catch (IOException e) { throw new HttpException("Failed URL: " + url, e); } }
/** * Returns HTTP response code. * * @return HTTP response code. */ public int responseCode() { try { connect(); return connection.getResponseCode(); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }
/** * Returns response message from server, such as "OK", or "Created", etc. * * @return response message from server, such as "OK", or "Created", etc. */ public String responseMessage() { try { connect(); return connection.getResponseMessage(); } catch (Exception e) { throw new HttpException("Failed URL: " + url, e); } }