Add Util.toHexString

PiperOrigin-RevId: 295539969
This commit is contained in:
ibaker 2020-02-17 10:04:56 +00:00 committed by Ian Baker
parent ed210bca4e
commit 0444e0b338
2 changed files with 23 additions and 0 deletions

View File

@ -1255,6 +1255,22 @@ public final class Util {
return data;
}
/**
* Returns a string containing a lower-case hex representation of the bytes provided.
*
* @param bytes The byte data to convert to hex.
* @return A String containing the hex representation of {@code bytes}.
*/
public static String toHexString(byte[] bytes) {
StringBuilder result = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
result
.append(Character.forDigit((bytes[i] >> 4) & 0xF, 16))
.append(Character.forDigit(bytes[i] & 0xF, 16));
}
return result.toString();
}
/**
* Returns a string with comma delimited simple names of each object's class.
*

View File

@ -705,6 +705,13 @@ public class UtilTest {
assertThat(Util.toLong(0xFEDCBA, 0x87654321)).isEqualTo(0xFEDCBA_87654321L);
}
@Test
public void testToHexString() {
byte[] bytes = TestUtil.createByteArray(0x12, 0xFC, 0x06);
assertThat(Util.toHexString(bytes)).isEqualTo("12fc06");
}
@Test
public void testGetCodecsOfType() {
assertThat(getCodecsOfType(null, C.TRACK_TYPE_VIDEO)).isNull();