Commit 0444e0b3 by ibaker Committed by Ian Baker

Add Util.toHexString

PiperOrigin-RevId: 295539969
parent ed210bca
...@@ -1256,6 +1256,22 @@ public final class Util { ...@@ -1256,6 +1256,22 @@ public final class Util {
} }
/** /**
* 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. * Returns a string with comma delimited simple names of each object's class.
* *
* @param objects The objects whose simple class names should be comma delimited and returned. * @param objects The objects whose simple class names should be comma delimited and returned.
......
...@@ -706,6 +706,13 @@ public class UtilTest { ...@@ -706,6 +706,13 @@ public class UtilTest {
} }
@Test @Test
public void testToHexString() {
byte[] bytes = TestUtil.createByteArray(0x12, 0xFC, 0x06);
assertThat(Util.toHexString(bytes)).isEqualTo("12fc06");
}
@Test
public void testGetCodecsOfType() { public void testGetCodecsOfType() {
assertThat(getCodecsOfType(null, C.TRACK_TYPE_VIDEO)).isNull(); assertThat(getCodecsOfType(null, C.TRACK_TYPE_VIDEO)).isNull();
assertThat(getCodecsOfType("avc1.64001e,vp9.63.1", C.TRACK_TYPE_AUDIO)).isNull(); assertThat(getCodecsOfType("avc1.64001e,vp9.63.1", C.TRACK_TYPE_AUDIO)).isNull();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment