@@ -0,0 +1,2570 @@
+package org.multibit.commons.utils;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.DataInputStream;%0Aimport java.io.DataOutputStream;%0Aimport java.io.IOException;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0A%0A/**%0A * %3Cp%3EUtility to provide the following to HTTPS application code:%3C/p%3E%0A * %3Cul%3E%0A * %3Cli%3EEasy access to HTTPS operations%3C/li%3E%0A * %3C/ul%3E%0A *%0A * @since 0.1.0%0A * %C2%A0%0A */%0Apublic class HttpsUtils %7B%0A%0A  private static final Logger log = LoggerFactory.getLogger(HttpsUtils.class);%0A%0A  /**%0A   * Utilities have a private constructor%0A   */%0A  private HttpsUtils() %7B%0A  %7D%0A%0A  /**%0A   * Perform a post of the specified bytes to the specified URL%0A   *%0A   * @param url         The URL to post to%0A   * @param payload     the bytes to post%0A   * @param contentType The content type (e.g. %22application/octet-stream%22)%0A   *%0A   * @return The bytes in the response payload%0A   */%0A  public static byte%5B%5D doPost(URL url, byte%5B%5D payload, String contentType) throws IOException %7B%0A%0A    // Send the encrypted request to the endpoint%0A    log.debug(%22Attempting to post %7B%7D bytes to URL %7B%7D%22, payload.length, url);%0A    URLConnection connection;%0A%0A    // URL connection channel%0A    connection = url.openConnection();%0A%0A    // Configure the request%0A    connection.setRequestProperty(%22Content-Length%22, String.valueOf(payload.length));%0A    connection.setRequestProperty(%22Content-Type%22, contentType);%0A    connection.setRequestProperty(%22Accept%22, %22*/*%22);%0A    // Let the server know that we want input%0A    connection.setDoInput(true);%0A    // Let the server know that we want to do output%0A    connection.setDoOutput(true);%0A    // No caching, we want the real thing%0A    connection.setUseCaches(false);%0A%0A    // Try to send the POST output%0A    try (DataOutputStream postOutputStream = new DataOutputStream(connection.getOutputStream())) %7B%0A      postOutputStream.write(payload);%0A      postOutputStream.flush();%0A    %7D%0A%0A    // Try to GET the response data%0A    try (DataInputStream responseInputStream = new DataInputStream(connection.getInputStream());%0A         ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream(1024)) %7B%0A%0A      byte readByte;%0A%0A      boolean keepGoing = true;%0A      while (keepGoing) %7B%0A        try %7B%0A          readByte = responseInputStream.readByte();%0A          responseOutputStream.write(readByte);%0A        %7D catch (IOException ioe) %7B%0A          // response is all read (EOFException) or has fallen over%0A          keepGoing = false;%0A        %7D%0A      %7D%0A      return responseOutputStream.toByteArray();%0A    %7D%0A%0A  %7D%0A%0A%7D%0A

Add HTTPS support