8
8
import java .util .*;
9
9
import java .util .stream .Collectors ;
10
10
import com .google .common .primitives .Bytes ;
11
+ import java .nio .charset .StandardCharsets ;
11
12
12
13
interface TargetHashingClient {
13
14
Map <String , String > hashAllBazelTargetsAndSourcefiles (Set <Path > seedFilepaths ) throws IOException , NoSuchAlgorithmException ;
@@ -17,6 +18,7 @@ interface TargetHashingClient {
17
18
class TargetHashingClientImpl implements TargetHashingClient {
18
19
private BazelClient bazelClient ;
19
20
private FilesClient files ;
21
+ private static final byte [] HEX_ARRAY = "0123456789abcdef" .getBytes (StandardCharsets .US_ASCII );
20
22
21
23
TargetHashingClientImpl (BazelClient bazelClient , FilesClient files ) {
22
24
this .bazelClient = bazelClient ;
@@ -136,11 +138,13 @@ private byte[] getDigestForSourceTargetName(
136
138
}
137
139
138
140
private String convertByteArrayToString (byte [] bytes ) {
139
- StringBuilder result = new StringBuilder ();
140
- for (byte aByte : bytes ) {
141
- result .append (String .format ("%02x" , aByte ));
141
+ byte [] hexChars = new byte [bytes .length * 2 ];
142
+ for (int j = 0 ; j < bytes .length ; j ++) {
143
+ int v = bytes [j ] & 0xFF ;
144
+ hexChars [j * 2 ] = HEX_ARRAY [v >>> 4 ];
145
+ hexChars [j * 2 + 1 ] = HEX_ARRAY [v & 0x0F ];
142
146
}
143
- return result . toString ( );
147
+ return new String ( hexChars , StandardCharsets . UTF_8 );
144
148
}
145
149
146
150
private String getNameForTarget (BazelTarget target ) {
0 commit comments