Add Util.toHexString
PiperOrigin-RevId: 295539969
This commit is contained in:
parent
ed210bca4e
commit
0444e0b338
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user