1 | |
package org.apache.archiva.checksum; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | 0 | public class Hex |
9 | |
{ |
10 | 0 | private static final byte[] DIGITS = "0123456789abcdef".getBytes(); |
11 | |
|
12 | |
public static String encode( byte[] data ) |
13 | |
{ |
14 | 0 | int l = data.length; |
15 | |
|
16 | 0 | byte[] raw = new byte[l * 2]; |
17 | |
|
18 | 0 | for ( int i = 0, j = 0; i < l; i++ ) |
19 | |
{ |
20 | 0 | raw[j++] = DIGITS[( 0xF0 & data[i] ) >>> 4]; |
21 | 0 | raw[j++] = DIGITS[0x0F & data[i]]; |
22 | |
} |
23 | |
|
24 | 0 | return new String( raw ); |
25 | |
} |
26 | |
|
27 | |
public static String encode( String raw ) |
28 | |
{ |
29 | 0 | return encode( raw.getBytes() ); |
30 | |
} |
31 | |
|
32 | |
} |