mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

Android and commons-codec problem #90

Closed lalkmim closed 8 years ago

lalkmim commented 10 years ago

If you try to use ttorrent on android you run into a NoMethodError due do android having an embedded commons-codec 1.2, while you're using commons-codec 1.8.

As far as I could see, you're using commons-codec for 2 simple operations that could be easily replaced. The 2 points that I found were:

1) DigestUtils.getSha1Digest() Could be replaced by the following code:

MessageDigest.getInstance("SHA-1")

2) Hex.encodeHex Could be replaced by the following code:

public static String byteArrayToHexString(byte[] bytes) {
    final char[] toDigits = "0123456789abcdef".toCharArray();
    int l = bytes.length;
    char[] out = new char[l << 1];

    int i = 0; for (int j = 0; i < l; ++i) {
        out[(j++)] = toDigits[((0xF0 & bytes[i]) >>> 4)];
        out[(j++)] = toDigits[(0xF & bytes[i])];
    }
    return new String(out);
}

Both codes were extracted from class files. The only thing to do other than the above is an exception that item 1) could throw.

philipphenkel commented 8 years ago

That is a duplicate of #144 No static method encodeHex in Android

mpetazzoni commented 8 years ago

Should be fixed now, thanks to @henkel PR.