88import java .util .*;
99import java .util .stream .Collectors ;
1010import com .google .common .primitives .Bytes ;
11+ import java .nio .charset .StandardCharsets ;
1112
1213interface TargetHashingClient {
1314 Map <String , String > hashAllBazelTargetsAndSourcefiles (Set <Path > seedFilepaths ) throws IOException , NoSuchAlgorithmException ;
@@ -17,6 +18,7 @@ interface TargetHashingClient {
1718class TargetHashingClientImpl implements TargetHashingClient {
1819 private BazelClient bazelClient ;
1920 private FilesClient files ;
21+ private static final byte [] HEX_ARRAY = "0123456789abcdef" .getBytes (StandardCharsets .US_ASCII );
2022
2123 TargetHashingClientImpl (BazelClient bazelClient , FilesClient files ) {
2224 this .bazelClient = bazelClient ;
@@ -136,11 +138,13 @@ private byte[] getDigestForSourceTargetName(
136138 }
137139
138140 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 ];
142146 }
143- return result . toString ( );
147+ return new String ( hexChars , StandardCharsets . UTF_8 );
144148 }
145149
146150 private String getNameForTarget (BazelTarget target ) {
0 commit comments