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

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

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

Util.fromUtf8Bytes介绍

[英]Returns a new String constructed by decoding UTF-8 encoded bytes.
[中]返回通过解码UTF-8编码字节构造的新字符串。

代码示例

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

  1. private static String toString(byte[] data) {
  2. if (data.length > 100) {
  3. return "<data is too long>";
  4. } else {
  5. return '\'' + Util.fromUtf8Bytes(data) + '\'';
  6. }
  7. }

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

  1. /**
  2. * Reads the next {@code length} bytes as UTF-8 characters. A terminating NUL byte is discarded,
  3. * if present.
  4. *
  5. * @param length The number of bytes to read.
  6. * @return The string, not including any terminating NUL byte.
  7. */
  8. public String readNullTerminatedString(int length) {
  9. if (length == 0) {
  10. return "";
  11. }
  12. int stringLength = length;
  13. int lastIndex = position + length - 1;
  14. if (lastIndex < limit && data[lastIndex] == 0) {
  15. stringLength--;
  16. }
  17. String result = Util.fromUtf8Bytes(data, position, stringLength);
  18. position += length;
  19. return result;
  20. }

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

  1. private static long getManifestPublishTimeMsInEmsg(EventMessage eventMessage) {
  2. try {
  3. return parseXsDateTime(Util.fromUtf8Bytes(eventMessage.messageData));
  4. } catch (ParserException ignored) {
  5. // if we can't parse this event, ignore
  6. return C.TIME_UNSET;
  7. }
  8. }

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

  1. public static String getString(Context context, String fileName) throws IOException {
  2. return Util.fromUtf8Bytes(getByteArray(context, fileName));
  3. }

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

  1. /**
  2. * Reads up to the next NUL byte (or the limit) as UTF-8 characters.
  3. *
  4. * @return The string not including any terminating NUL byte, or null if the end of the data has
  5. * already been reached.
  6. */
  7. public @Nullable String readNullTerminatedString() {
  8. if (bytesLeft() == 0) {
  9. return null;
  10. }
  11. int stringLimit = position;
  12. while (stringLimit < limit && data[stringLimit] != 0) {
  13. stringLimit++;
  14. }
  15. String string = Util.fromUtf8Bytes(data, position, stringLimit - position);
  16. position = stringLimit;
  17. if (position < limit) {
  18. position++;
  19. }
  20. return string;
  21. }

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

  1. | (initializationBytes[29] & 0xFF);
  2. String fontFamily =
  3. Util.fromUtf8Bytes(initializationBytes, 43, initializationBytes.length - 43);
  4. defaultFontFamily = TX3G_SERIF.equals(fontFamily) ? C.SERIF_NAME : C.SANS_SERIF_NAME;

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

  1. JSONObject responseJson = new JSONObject(Util.fromUtf8Bytes(response));
  2. StringBuilder adjustedResponseBuilder = new StringBuilder("{\"keys\":[");
  3. JSONArray keysArray = responseJson.getJSONArray("keys");
  4. return Util.getUtf8Bytes(adjustedResponseBuilder.toString());
  5. } catch (JSONException e) {
  6. Log.e(TAG, "Failed to adjust response data: " + Util.fromUtf8Bytes(response), e);
  7. return response;

代码示例来源: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. /**
  2. * @param initializationData Optional initialization data for the decoder. If not null or empty,
  3. * the initialization data must consist of two byte arrays. The first must contain an SSA
  4. * format line. The second must contain an SSA header that will be assumed common to all
  5. * samples.
  6. */
  7. public SsaDecoder(List<byte[]> initializationData) {
  8. super("SsaDecoder");
  9. if (initializationData != null && !initializationData.isEmpty()) {
  10. haveInitializationData = true;
  11. String formatLine = Util.fromUtf8Bytes(initializationData.get(0));
  12. Assertions.checkArgument(formatLine.startsWith(FORMAT_LINE_PREFIX));
  13. parseFormatLine(formatLine);
  14. parseHeader(new ParsableByteArray(initializationData.get(1)));
  15. } else {
  16. haveInitializationData = false;
  17. }
  18. }

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

  1. @Override
  2. public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
  3. String url =
  4. request.getDefaultUrl() + "&signedRequest=" + Util.fromUtf8Bytes(request.getData());
  5. return executePost(dataSourceFactory, url, Util.EMPTY_BYTE_ARRAY, null);
  6. }

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

  1. String line = Util.fromUtf8Bytes(data, position, lineLimit - position);
  2. position = lineLimit;
  3. if (position == limit) {

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

  1. public static String getString(Context context, String fileName) throws IOException {
  2. return Util.fromUtf8Bytes(getByteArray(context, fileName));
  3. }

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

  1. private static Cue parseVttCueBox(ParsableByteArray sampleData, WebvttCue.Builder builder,
  2. int remainingCueBoxBytes) throws SubtitleDecoderException {
  3. builder.reset();
  4. while (remainingCueBoxBytes > 0) {
  5. if (remainingCueBoxBytes < BOX_HEADER_SIZE) {
  6. throw new SubtitleDecoderException("Incomplete vtt cue box header found.");
  7. }
  8. int boxSize = sampleData.readInt();
  9. int boxType = sampleData.readInt();
  10. remainingCueBoxBytes -= BOX_HEADER_SIZE;
  11. int payloadLength = boxSize - BOX_HEADER_SIZE;
  12. String boxPayload =
  13. Util.fromUtf8Bytes(sampleData.data, sampleData.getPosition(), payloadLength);
  14. sampleData.skipBytes(payloadLength);
  15. remainingCueBoxBytes -= payloadLength;
  16. if (boxType == TYPE_sttg) {
  17. WebvttCueParser.parseCueSettingsList(boxPayload, builder);
  18. } else if (boxType == TYPE_payl) {
  19. WebvttCueParser.parseCueText(null, boxPayload.trim(), builder, Collections.emptyList());
  20. } else {
  21. // Other VTTCueBox children are still not supported and are ignored.
  22. }
  23. }
  24. return builder.build();
  25. }

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

  1. @Test
  2. public void testPartialReads() throws IOException {
  3. byte[] buffer = new byte[18];
  4. DataSpec dataSpec = buildDataSpec("data:,012345678901234567");
  5. assertThat(schemeDataDataSource.open(dataSpec)).isEqualTo(18);
  6. assertThat(schemeDataDataSource.read(buffer, 0, 9)).isEqualTo(9);
  7. assertThat(schemeDataDataSource.read(buffer, 3, 0)).isEqualTo(0);
  8. assertThat(schemeDataDataSource.read(buffer, 9, 15)).isEqualTo(9);
  9. assertThat(schemeDataDataSource.read(buffer, 1, 0)).isEqualTo(0);
  10. assertThat(schemeDataDataSource.read(buffer, 1, 1)).isEqualTo(RESULT_END_OF_INPUT);
  11. assertThat(Util.fromUtf8Bytes(buffer, 0, 18)).isEqualTo("012345678901234567");
  12. }

代码示例来源:origin: lizixian18/StarrySky

  1. CHANNEL_ID,
  2. Util.fromUtf8Bytes(taskState.action.data));
  3. } else if (taskState.state == TaskState.STATE_FAILED) {
  4. CHANNEL_ID,
  5. Util.fromUtf8Bytes(taskState.action.data));

相关文章