class ElasticApmAttacher {

    static String md5Hash(InputStream resourceAsStream) throws IOException, NoSuchAlgorithmException {
        try (InputStream agentJar = resourceAsStream) {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[1024];
            DigestInputStream dis = new DigestInputStream(agentJar, md);
            while (dis.read(buffer) != -1) {}
            return String.format("%032x", new BigInteger(1, md.digest()));
        }
    }

}