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

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

本文整理了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

private static void setSampleDuration(byte[] subripSampleData, long durationUs,
  String timecodeFormat, int endTimecodeOffset, long lastTimecodeValueScalingFactor,
  byte[] emptyTimecode) {
 byte[] timeCodeData;
 if (durationUs == C.TIME_UNSET) {
  timeCodeData = emptyTimecode;
 } else {
  int hours = (int) (durationUs / (3600 * C.MICROS_PER_SECOND));
  durationUs -= (hours * 3600 * C.MICROS_PER_SECOND);
  int minutes = (int) (durationUs / (60 * C.MICROS_PER_SECOND));
  durationUs -= (minutes * 60 * C.MICROS_PER_SECOND);
  int seconds = (int) (durationUs / C.MICROS_PER_SECOND);
  durationUs -= (seconds * C.MICROS_PER_SECOND);
  int lastValue = (int) (durationUs / lastTimecodeValueScalingFactor);
  timeCodeData = Util.getUtf8Bytes(String.format(Locale.US, timecodeFormat, hours, minutes,
    seconds, lastValue));
 }
 System.arraycopy(timeCodeData, 0, subripSampleData, endTimecodeOffset, emptyTimecode.length);
}

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

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

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

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

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

@Config(sdk = 26)
@Test
public void testAdjustRequestDataV26() {
 // We expect "+" and "/" to be replaced with "-" and "_" respectively, for "kids".
 byte[] expected =
   Util.getUtf8Bytes(
     "{"
       + "\"kids\":["
       + "\"abc-def_\","
       + "\"ab-cde_f\""
       + "],"
       + "\"type\":\"temporary\""
       + "}");
 assertThat(ClearKeyUtil.adjustRequestData(KEY_REQUEST)).isEqualTo(expected);
}

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

@Config(sdk = 26)
@Test
public void testAdjustSingleKeyResponseDataV26() {
 // Everything but the keys should be removed. Within each key only the k, kid and kty parameters
 // should remain. Any "-" and "_" characters in the k and kid values should be replaced with "+"
 // and "/".
 byte[] expected =
   Util.getUtf8Bytes(
     "{"
       + "\"keys\":["
       + "{"
       + "\"k\":\"abc/def+\",\"kid\":\"ab/cde+f\",\"kty\":\"o_c-t\""
       + "}"
       + "]"
       + "}");
 assertThat(ClearKeyUtil.adjustResponseData(SINGLE_KEY_RESPONSE)).isEqualTo(expected);
}

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

@Config(sdk = 26)
@Test
public void testAdjustMultiKeyResponseDataV26() {
 // Everything but the keys should be removed. Within each key only the k, kid and kty parameters
 // should remain. Any "-" and "_" characters in the k and kid values should be replaced with "+"
 // and "/".
 byte[] expected =
   Util.getUtf8Bytes(
     "{"
       + "\"keys\":["
       + "{"
       + "\"k\":\"abc/def+\",\"kid\":\"ab/cde+f\",\"kty\":\"oct\""
       + "},{"
       + "\"k\":\"ghi/jkl+\",\"kid\":\"gh/ijk+l\",\"kty\":\"oct\""
       + "}"
       + "]"
       + "}");
 assertThat(ClearKeyUtil.adjustResponseData(MULTI_KEY_RESPONSE)).isEqualTo(expected);
}

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

@Test
public void testBase64Data() throws IOException {
 DataSpec dataSpec = buildDataSpec("data:text/plain;base64,eyJwcm92aWRlciI6IndpZGV2aW5lX3Rlc3QiL"
   + "CJjb250ZW50X2lkIjoiTWpBeE5WOTBaV0Z5Y3c9PSIsImtleV9pZHMiOlsiMDAwMDAwMDAwMDAwMDAwMDAwMDAwM"
   + "DAwMDAwMDAwMDAiXX0=");
 DataSourceAsserts.assertDataSourceContent(
   schemeDataDataSource,
   dataSpec,
   Util.getUtf8Bytes(
     "{\"provider\":\"widevine_test\",\"content_id\":\"MjAxNV90ZWFycw==\",\"key_ids\":"
       + "[\"00000000000000000000000000000000\"]}"));
}

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

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

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

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

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

@Test
public void testStoreAndLoadActions() throws Exception {
 doTestSerializationRoundTrip(
   new DownloadAction[] {
    new FakeDownloadAction("type1", Util.getUtf8Bytes("123")),
    new FakeDownloadAction("type2", Util.getUtf8Bytes("321")),
   },
   new FakeDeserializer("type1"),
   new FakeDeserializer("type2"));
}

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

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

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

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

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

@Test
public void testRead_nonAmrSignature_throwParserException()
  throws IOException, InterruptedException {
 AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
 FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR-WB\n"));
 try {
  amrExtractor.read(input, new PositionHolder());
  fail();
 } catch (ParserException e) {
  // expected
 }
}

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

@Test
public void testLoadActions() throws Exception {
 byte[] data1 = Util.getUtf8Bytes("123");
 byte[] data2 = Util.getUtf8Bytes("321");
 DownloadAction[] actions =
   loadActions(
     new Object[] {
      ActionFile.VERSION,
      2, // Action count
      "type1", // Action 1
      FakeDownloadAction.VERSION,
      data1,
      "type2", // Action 2
      FakeDownloadAction.VERSION,
      data2,
     },
     new FakeDeserializer("type1"),
     new FakeDeserializer("type2"));
 assertThat(actions).isNotNull();
 assertThat(actions).hasLength(2);
 assertAction(actions[0], "type1", FakeDownloadAction.VERSION, data1);
 assertAction(actions[1], "type2", FakeDownloadAction.VERSION, data2);
}

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

@Test
public void testLoadAction() throws Exception {
 byte[] data = Util.getUtf8Bytes("321");
 DownloadAction[] actions =
   loadActions(
     new Object[] {
      ActionFile.VERSION,
      1, // Action count
      "type2", // Action 1
      FakeDownloadAction.VERSION,
      data,
     },
     new FakeDeserializer("type2"));
 assertThat(actions).isNotNull();
 assertThat(actions).hasLength(1);
 assertAction(actions[0], "type2", FakeDownloadAction.VERSION, data);
}

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

@Test
public void testLoadNotSupportedType() throws Exception {
 try {
  loadActions(
    new Object[] {
     ActionFile.VERSION,
     1, // Action count
     "type2", // Action 1
     FakeDownloadAction.VERSION,
     Util.getUtf8Bytes("321"),
    },
    new FakeDeserializer("type1"));
  Assert.fail();
 } catch (DownloadException e) {
  // Expected exception.
 }
}

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

@Test
public void testLoadNotSupportedVersion() throws Exception {
 try {
  loadActions(
    new Object[] {
     ActionFile.VERSION + 1,
     1, // Action count
     "type2", // Action 1
     FakeDownloadAction.VERSION,
     Util.getUtf8Bytes("321"),
    },
    new FakeDeserializer("type2"));
  Assert.fail();
 } catch (IOException e) {
  // Expected exception.
 }
}

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

@Test
public void testLoadNotSupportedActionVersion() throws Exception {
 try {
  loadActions(
    new Object[] {
     ActionFile.VERSION,
     1, // Action count
     "type2", // Action 1
     FakeDownloadAction.VERSION + 1,
     Util.getUtf8Bytes("321"),
    },
    new FakeDeserializer("type2"));
  Assert.fail();
 } catch (IOException e) {
  // Expected exception.
 }
}

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

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

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

private void assertParserProduces(WebvttCssStyle expected,
  String styleBlock){
 ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(styleBlock));
 WebvttCssStyle actualElem = parser.parseBlock(input);
 assertThat(actualElem.hasBackgroundColor()).isEqualTo(expected.hasBackgroundColor());
 if (expected.hasBackgroundColor()) {
  assertThat(actualElem.getBackgroundColor()).isEqualTo(expected.getBackgroundColor());
 }
 assertThat(actualElem.hasFontColor()).isEqualTo(expected.hasFontColor());
 if (expected.hasFontColor()) {
  assertThat(actualElem.getFontColor()).isEqualTo(expected.getFontColor());
 }
 assertThat(actualElem.getFontFamily()).isEqualTo(expected.getFontFamily());
 assertThat(actualElem.getFontSize()).isEqualTo(expected.getFontSize());
 assertThat(actualElem.getFontSizeUnit()).isEqualTo(expected.getFontSizeUnit());
 assertThat(actualElem.getStyle()).isEqualTo(expected.getStyle());
 assertThat(actualElem.isLinethrough()).isEqualTo(expected.isLinethrough());
 assertThat(actualElem.isUnderline()).isEqualTo(expected.isUnderline());
 assertThat(actualElem.getTextAlign()).isEqualTo(expected.getTextAlign());
}

相关文章