// Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
//   public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
//     try (InputStream is = entity.getContent()) {
//       byte[] buffer = new byte[1024];
// 
//       MessageDigest md = MessageDigest.getInstance(algorithm);
// 
//       int numRead;
// 
//       do {
//         numRead = is.read(buffer);
// 
//         if (numRead > 0) {
//           md.update(buffer, 0, numRead);
//         }
//       } while (numRead != -1);
// 
//       return new String(encodeHex(md.digest()));
//     } catch (NoSuchAlgorithmException e) {
//       throw new IOException(e);
//     }
//   }
// 
//   private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
// 
//   public static char[] encodeHex(byte[] data) {
//     int l = data.length;
// 
//     char[] out = new char[l << 1];
// 
//     // two characters form the hex value.
//     for (int i = 0, j = 0; i < l; i++) {
//       out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
//       out[j++] = DIGITS[0x0F & data[i]];
//     }
// 
//     return out;
//   }
// 
// }


import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.Digests;
import de.pdark.decentxml.Document;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter;
      throws IOException {
    StringBuilder path = new StringBuilder();

    path.append(groupId.replace('.', '/')).append('/');
    path.append(artifactId).append('/');
    path.append(version).append('/');
    path.append(artifactId).append('-').append(version).append(extension);

    HttpPut httpPut = new HttpPut(repoUrl + path);
    httpPut.setEntity(entity);

    HttpResponse response;
    try {
      response = httpclient.execute(httpPut);

      try {
        EntityUtils.consume(response.getEntity());
      } finally {
        httpPut.releaseConnection();
      }
    } catch (IOException e) {
      throw new IOException("IOException executing " + httpPut.toString(), e);
    }

    if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() > 299) {
      throw new IOException(httpPut.toString() + " : " + response.getStatusLine().toString());
    }
  }

  public static StringEntity getDigest(HttpEntity entity, String algorithm) throws IOException {
// Path: src/main/java/com/sonatype/nexus/perftest/Digests.java
// public class Digests {
//   public static String getDigest(HttpEntity entity, String algorithm) throws IOException {
//     try (InputStream is = entity.getContent()) {
//       byte[] buffer = new byte[1024];
// 
//       MessageDigest md = MessageDigest.getInstance(algorithm);
// 
//       int numRead;
// 
//       do {
//         numRead = is.read(buffer);
// 
//         if (numRead > 0) {
//           md.update(buffer, 0, numRead);
//         }
//       } while (numRead != -1);
// 
//       return new String(encodeHex(md.digest()));
//     } catch (NoSuchAlgorithmException e) {
//       throw new IOException(e);
//     }
//   }
// 
//   private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
// 
//   public static char[] encodeHex(byte[] data) {
//     int l = data.length;
// 
//     char[] out = new char[l << 1];
// 
//     // two characters form the hex value.
//     for (int i = 0, j = 0; i < l; i++) {
//       out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
//       out[j++] = DIGITS[0x0F & data[i]];
//     }
// 
//     return out;
//   }
// 
// }


// Path: src/main/java/com/sonatype/nexus/perftest/maven/ArtifactDeployer.java
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.sonatype.nexus.perftest.Digests;
import de.pdark.decentxml.Document;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter;

      throws IOException {
    StringBuilder path = new StringBuilder();

    path.append(groupId.replace('.', '/')).append('/');
    path.append(artifactId).append('/');
    path.append(version).append('/');
    path.append(artifactId).append('-').append(version).append(extension);

    HttpPut httpPut = new HttpPut(repoUrl + path);
    httpPut.setEntity(entity);

    HttpResponse response;
    try {
      response = httpclient.execute(httpPut);

      try {
        EntityUtils.consume(response.getEntity());
      } finally {
        httpPut.releaseConnection();
      }
    } catch (IOException e) {
      throw new IOException("IOException executing " + httpPut.toString(), e);
    }

    if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() > 299) {
      throw new IOException(httpPut.toString() + " : " + response.getStatusLine().toString());
    }
  }

  public static StringEntity getDigest(HttpEntity entity, String algorithm) throws IOException {
    return new StringEntity(Digests.getDigest(entity, algorithm), ContentType.TEXT_PLAIN);