com.google.android.exoplayer2.util.Util.getUtf8Bytes()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中com.google.android.exoplayer2.util.Util.getUtf8Bytes()方法的一些代码示例,展示了Util.getUtf8Bytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getUtf8Bytes()方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util
方法名:getUtf8Bytes

Util.getUtf8Bytes介绍

[英]Returns a new byte array containing the code points of a String encoded using UTF-8.
[中]返回一个新字节数组,其中包含使用UTF-8编码的字符串的代码点。

代码示例

代码示例来源:origin: google/ExoPlayer

  1. private static void setSampleDuration(byte[] subripSampleData, long durationUs,
  2. String timecodeFormat, int endTimecodeOffset, long lastTimecodeValueScalingFactor,
  3. byte[] emptyTimecode) {
  4. byte[] timeCodeData;
  5. if (durationUs == C.TIME_UNSET) {
  6. timeCodeData = emptyTimecode;
  7. } else {
  8. int hours = (int) (durationUs / (3600 * C.MICROS_PER_SECOND));
  9. durationUs -= (hours * 3600 * C.MICROS_PER_SECOND);
  10. int minutes = (int) (durationUs / (60 * C.MICROS_PER_SECOND));
  11. durationUs -= (minutes * 60 * C.MICROS_PER_SECOND);
  12. int seconds = (int) (durationUs / C.MICROS_PER_SECOND);
  13. durationUs -= (seconds * C.MICROS_PER_SECOND);
  14. int lastValue = (int) (durationUs / lastTimecodeValueScalingFactor);
  15. timeCodeData = Util.getUtf8Bytes(String.format(Locale.US, timecodeFormat, hours, minutes,
  16. seconds, lastValue));
  17. }
  18. System.arraycopy(timeCodeData, 0, subripSampleData, endTimecodeOffset, emptyTimecode.length);
  19. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Adjusts ClearKey request data obtained from the Android ClearKey CDM to be spec compliant.
  3. *
  4. * @param request The request data.
  5. * @return The adjusted request data.
  6. */
  7. public static byte[] adjustRequestData(byte[] request) {
  8. if (Util.SDK_INT >= 27) {
  9. return request;
  10. }
  11. // Prior to O-MR1 the ClearKey CDM encoded the values in the "kids" array using Base64 encoding
  12. // rather than Base64Url encoding. See [Internal: b/64388098]. We know the exact request format
  13. // from the platform's InitDataParser.cpp. Since there aren't any "+" or "/" symbols elsewhere
  14. // in the request, it's safe to fix the encoding by replacement through the whole request.
  15. String requestString = Util.fromUtf8Bytes(request);
  16. return Util.getUtf8Bytes(base64ToBase64Url(requestString));
  17. }

代码示例来源:origin: google/ExoPlayer

  1. private static void assertParseStringToLong(
  2. long expected, ParsingLoadable.Parser<Long> parser, String data) throws IOException {
  3. long actual = parser.parse(null, new ByteArrayInputStream(Util.getUtf8Bytes(data)));
  4. assertThat(actual).isEqualTo(expected);
  5. }
  6. }

代码示例来源:origin: google/ExoPlayer

  1. @Config(sdk = 26)
  2. @Test
  3. public void testAdjustRequestDataV26() {
  4. // We expect "+" and "/" to be replaced with "-" and "_" respectively, for "kids".
  5. byte[] expected =
  6. Util.getUtf8Bytes(
  7. "{"
  8. + "\"kids\":["
  9. + "\"abc-def_\","
  10. + "\"ab-cde_f\""
  11. + "],"
  12. + "\"type\":\"temporary\""
  13. + "}");
  14. assertThat(ClearKeyUtil.adjustRequestData(KEY_REQUEST)).isEqualTo(expected);
  15. }

代码示例来源:origin: google/ExoPlayer

  1. @Config(sdk = 26)
  2. @Test
  3. public void testAdjustSingleKeyResponseDataV26() {
  4. // Everything but the keys should be removed. Within each key only the k, kid and kty parameters
  5. // should remain. Any "-" and "_" characters in the k and kid values should be replaced with "+"
  6. // and "/".
  7. byte[] expected =
  8. Util.getUtf8Bytes(
  9. "{"
  10. + "\"keys\":["
  11. + "{"
  12. + "\"k\":\"abc/def+\",\"kid\":\"ab/cde+f\",\"kty\":\"o_c-t\""
  13. + "}"
  14. + "]"
  15. + "}");
  16. assertThat(ClearKeyUtil.adjustResponseData(SINGLE_KEY_RESPONSE)).isEqualTo(expected);
  17. }

代码示例来源:origin: google/ExoPlayer

  1. @Config(sdk = 26)
  2. @Test
  3. public void testAdjustMultiKeyResponseDataV26() {
  4. // Everything but the keys should be removed. Within each key only the k, kid and kty parameters
  5. // should remain. Any "-" and "_" characters in the k and kid values should be replaced with "+"
  6. // and "/".
  7. byte[] expected =
  8. Util.getUtf8Bytes(
  9. "{"
  10. + "\"keys\":["
  11. + "{"
  12. + "\"k\":\"abc/def+\",\"kid\":\"ab/cde+f\",\"kty\":\"oct\""
  13. + "},{"
  14. + "\"k\":\"ghi/jkl+\",\"kid\":\"gh/ijk+l\",\"kty\":\"oct\""
  15. + "}"
  16. + "]"
  17. + "}");
  18. assertThat(ClearKeyUtil.adjustResponseData(MULTI_KEY_RESPONSE)).isEqualTo(expected);
  19. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testBase64Data() throws IOException {
  3. DataSpec dataSpec = buildDataSpec("data:text/plain;base64,eyJwcm92aWRlciI6IndpZGV2aW5lX3Rlc3QiL"
  4. + "CJjb250ZW50X2lkIjoiTWpBeE5WOTBaV0Z5Y3c9PSIsImtleV9pZHMiOlsiMDAwMDAwMDAwMDAwMDAwMDAwMDAwM"
  5. + "DAwMDAwMDAwMDAiXX0=");
  6. DataSourceAsserts.assertDataSourceContent(
  7. schemeDataDataSource,
  8. dataSpec,
  9. Util.getUtf8Bytes(
  10. "{\"provider\":\"widevine_test\",\"content_id\":\"MjAxNV90ZWFycw==\",\"key_ids\":"
  11. + "[\"00000000000000000000000000000000\"]}"));
  12. }

代码示例来源:origin: google/ExoPlayer

  1. private void assertInputLimit(String expectedLine, String s) {
  2. ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(s));
  3. CssParser.skipStyleBlock(input);
  4. assertThat(input.readLine()).isEqualTo(expectedLine);
  5. }

代码示例来源:origin: google/ExoPlayer

  1. private void assertSkipsToEndOfSkip(String expectedLine, String s) {
  2. ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(s));
  3. CssParser.skipWhitespaceAndComments(input);
  4. assertThat(input.readLine()).isEqualTo(expectedLine);
  5. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testStoreAndLoadActions() throws Exception {
  3. doTestSerializationRoundTrip(
  4. new DownloadAction[] {
  5. new FakeDownloadAction("type1", Util.getUtf8Bytes("123")),
  6. new FakeDownloadAction("type2", Util.getUtf8Bytes("321")),
  7. },
  8. new FakeDeserializer("type1"),
  9. new FakeDeserializer("type2"));
  10. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testAsciiData() throws IOException {
  3. DataSourceAsserts.assertDataSourceContent(
  4. schemeDataDataSource,
  5. buildDataSpec("data:,A%20brief%20note"),
  6. Util.getUtf8Bytes("A brief note"));
  7. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testSniff_nonAmrSignature_returnFalse() throws IOException, InterruptedException {
  3. AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
  4. FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR\n123"));
  5. boolean result = amrExtractor.sniff(input);
  6. assertThat(result).isFalse();
  7. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testRead_nonAmrSignature_throwParserException()
  3. throws IOException, InterruptedException {
  4. AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
  5. FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR-WB\n"));
  6. try {
  7. amrExtractor.read(input, new PositionHolder());
  8. fail();
  9. } catch (ParserException e) {
  10. // expected
  11. }
  12. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testLoadActions() throws Exception {
  3. byte[] data1 = Util.getUtf8Bytes("123");
  4. byte[] data2 = Util.getUtf8Bytes("321");
  5. DownloadAction[] actions =
  6. loadActions(
  7. new Object[] {
  8. ActionFile.VERSION,
  9. 2, // Action count
  10. "type1", // Action 1
  11. FakeDownloadAction.VERSION,
  12. data1,
  13. "type2", // Action 2
  14. FakeDownloadAction.VERSION,
  15. data2,
  16. },
  17. new FakeDeserializer("type1"),
  18. new FakeDeserializer("type2"));
  19. assertThat(actions).isNotNull();
  20. assertThat(actions).hasLength(2);
  21. assertAction(actions[0], "type1", FakeDownloadAction.VERSION, data1);
  22. assertAction(actions[1], "type2", FakeDownloadAction.VERSION, data2);
  23. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testLoadAction() throws Exception {
  3. byte[] data = Util.getUtf8Bytes("321");
  4. DownloadAction[] actions =
  5. loadActions(
  6. new Object[] {
  7. ActionFile.VERSION,
  8. 1, // Action count
  9. "type2", // Action 1
  10. FakeDownloadAction.VERSION,
  11. data,
  12. },
  13. new FakeDeserializer("type2"));
  14. assertThat(actions).isNotNull();
  15. assertThat(actions).hasLength(1);
  16. assertAction(actions[0], "type2", FakeDownloadAction.VERSION, data);
  17. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testLoadNotSupportedType() throws Exception {
  3. try {
  4. loadActions(
  5. new Object[] {
  6. ActionFile.VERSION,
  7. 1, // Action count
  8. "type2", // Action 1
  9. FakeDownloadAction.VERSION,
  10. Util.getUtf8Bytes("321"),
  11. },
  12. new FakeDeserializer("type1"));
  13. Assert.fail();
  14. } catch (DownloadException e) {
  15. // Expected exception.
  16. }
  17. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testLoadNotSupportedVersion() throws Exception {
  3. try {
  4. loadActions(
  5. new Object[] {
  6. ActionFile.VERSION + 1,
  7. 1, // Action count
  8. "type2", // Action 1
  9. FakeDownloadAction.VERSION,
  10. Util.getUtf8Bytes("321"),
  11. },
  12. new FakeDeserializer("type2"));
  13. Assert.fail();
  14. } catch (IOException e) {
  15. // Expected exception.
  16. }
  17. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testLoadNotSupportedActionVersion() throws Exception {
  3. try {
  4. loadActions(
  5. new Object[] {
  6. ActionFile.VERSION,
  7. 1, // Action count
  8. "type2", // Action 1
  9. FakeDownloadAction.VERSION + 1,
  10. Util.getUtf8Bytes("321"),
  11. },
  12. new FakeDeserializer("type2"));
  13. Assert.fail();
  14. } catch (IOException e) {
  15. // Expected exception.
  16. }
  17. }

代码示例来源:origin: google/ExoPlayer

  1. @Test
  2. public void testParseSampleAesCtrMethod() throws Exception {
  3. Uri playlistUri = Uri.parse("https://example.com/test.m3u8");
  4. String playlistString =
  5. "#EXTM3U\n"
  6. + "#EXT-X-MEDIA-SEQUENCE:0\n"
  7. + "#EXTINF:8,\n"
  8. + "https://priv.example.com/1.ts\n"
  9. + "\n"
  10. + "#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="
  11. + "\"data:text/plain;base64,VGhpcyBpcyBhbiBlYXN0ZXIgZWdn\","
  12. + "IV=0x9358382AEB449EE23C3D809DA0B9CCD3,KEYFORMATVERSIONS=\"1\","
  13. + "KEYFORMAT=\"com.widevine\",IV=0x1566B\n"
  14. + "#EXTINF:8,\n"
  15. + "https://priv.example.com/2.ts\n"
  16. + "#EXT-X-ENDLIST\n";
  17. InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
  18. HlsMediaPlaylist playlist =
  19. (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
  20. assertThat(playlist.protectionSchemes.schemeType).isEqualTo(C.CENC_TYPE_cenc);
  21. assertThat(playlist.protectionSchemes.get(0).matches(C.WIDEVINE_UUID)).isTrue();
  22. assertThat(playlist.protectionSchemes.get(0).hasData()).isFalse();
  23. }

代码示例来源:origin: google/ExoPlayer

  1. private void assertParserProduces(WebvttCssStyle expected,
  2. String styleBlock){
  3. ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(styleBlock));
  4. WebvttCssStyle actualElem = parser.parseBlock(input);
  5. assertThat(actualElem.hasBackgroundColor()).isEqualTo(expected.hasBackgroundColor());
  6. if (expected.hasBackgroundColor()) {
  7. assertThat(actualElem.getBackgroundColor()).isEqualTo(expected.getBackgroundColor());
  8. }
  9. assertThat(actualElem.hasFontColor()).isEqualTo(expected.hasFontColor());
  10. if (expected.hasFontColor()) {
  11. assertThat(actualElem.getFontColor()).isEqualTo(expected.getFontColor());
  12. }
  13. assertThat(actualElem.getFontFamily()).isEqualTo(expected.getFontFamily());
  14. assertThat(actualElem.getFontSize()).isEqualTo(expected.getFontSize());
  15. assertThat(actualElem.getFontSizeUnit()).isEqualTo(expected.getFontSizeUnit());
  16. assertThat(actualElem.getStyle()).isEqualTo(expected.getStyle());
  17. assertThat(actualElem.isLinethrough()).isEqualTo(expected.isLinethrough());
  18. assertThat(actualElem.isUnderline()).isEqualTo(expected.isUnderline());
  19. assertThat(actualElem.getTextAlign()).isEqualTo(expected.getTextAlign());
  20. }

相关文章