/** * Sets authentication info * * @param user HTTP API username * @param pass HTTP API password */ public void setAuth(String user, String pass) { if (user != null && pass != null) { String auth = user + ":" + pass; authEncoded = Base64.encodeBytes(auth.getBytes()).toString(); } else { authEncoded = null; } }
public byte[] download(String pathToDownload) throws IOException, URISyntaxException { try { final URL url = new URL(pathToDownload); final URLConnection uc = getUrlConnection(url); final InputStream is = uc.getInputStream(); final InputStreamReader isr = new InputStreamReader(is); final BufferedReader rd = new BufferedReader(isr, 8192); final StringBuilder sb = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); return Base64.decode(sb.toString().replace("<html>", "").replace("</html>", "")); } catch (Exception e) { return null; } }