[ https://issues.apache.org/jira/browse/MAPREDUCE-7333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17313408#comment-17313408 ]
Marcono1234 commented on MAPREDUCE-7333: ---------------------------------------- That would probably work as well, though I don't think that a call to {{Integer.toHexString}} will be a performance problem. If you decide to use the array approach, it might be good to: - Make the array a {{static final}} field to avoid creating it every time the method is called. Though maybe using a local array is actually more performant? I am not very familiar with performance tuning in this regard; maybe the compiler or the JVM performs escape analysis and only allocates the array on the stack. - Storing only {{char}} inside the array (instead of {{String}}); StringBuilder has an {{append(char)}} method which can then be used > SecureShuffleUtils.toHex(byte[]) creates malformed hex string > ------------------------------------------------------------- > > Key: MAPREDUCE-7333 > URL: https://issues.apache.org/jira/browse/MAPREDUCE-7333 > Project: Hadoop Map/Reduce > Issue Type: Bug > Affects Versions: 3.2.2 > Reporter: Marcono1234 > Priority: Major > > {{org.apache.hadoop.mapreduce.security.SecureShuffleUtils.toHex(byte[])}} > creates malformed hex strings: > {code} > for (byte b : ba) { > ps.printf("%x", b); > } > {code} > The pattern {{"%x"}} would for bytes < 16 only have on hex char and for > example both {{1, 0}} and {{16}} would have the result {{"10"}}. > A correct (and more efficient) implementation would be: > {code} > public static String toHex(byte[] ba) { > StringBuilder sb = new StringBuilder(ba.length * 2); > for (byte b : ba) { > int unsignedB = b & 0xFF; > if (unsignedB < 16) { > sb.append('0'); > } > sb.append(Integer.toHexString(unsignedB)); > } > return sb.toString(); > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: mapreduce-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: mapreduce-issues-h...@hadoop.apache.org