Add Util.getUtf8Bytes to avoid warnings

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128980489
This commit is contained in:
olly 2016-08-01 06:31:45 -07:00 committed by Oliver Woodman
parent 3604d589c1
commit abd5653dc4
3 changed files with 18 additions and 6 deletions

View file

@ -17,6 +17,7 @@ package com.google.android.exoplayer2.text.webvtt;
import android.test.InstrumentationTestCase;
import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util;
/**
* Unit test for {@link CssParser}.
@ -122,7 +123,7 @@ public final class CssParserTest extends InstrumentationTestCase {
public void testGetNextToken() {
String stringInput = " lorem:ipsum\n{dolor}#sit,amet;lorem:ipsum\r\t\f\ndolor(())\n";
ParsableByteArray input = new ParsableByteArray(stringInput.getBytes());
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(stringInput));
StringBuilder builder = new StringBuilder();
assertEquals(CssParser.parseNextToken(input, builder), "lorem");
assertEquals(CssParser.parseNextToken(input, builder), ":");
@ -178,20 +179,20 @@ public final class CssParserTest extends InstrumentationTestCase {
// Utility methods.
private void assertSkipsToEndOfSkip(String expectedLine, String s) {
ParsableByteArray input = new ParsableByteArray(s.getBytes());
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(s));
CssParser.skipWhitespaceAndComments(input);
assertEquals(expectedLine, input.readLine());
}
private void assertInputLimit(String expectedLine, String s) {
ParsableByteArray input = new ParsableByteArray(s.getBytes());
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(s));
CssParser.skipStyleBlock(input);
assertEquals(expectedLine, input.readLine());
}
private void assertParserProduces(WebvttCssStyle expected,
String styleBlock){
ParsableByteArray input = new ParsableByteArray(styleBlock.getBytes());
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(styleBlock));
WebvttCssStyle actualElem = parser.parseBlock(input);
assertEquals(expected.hasBackgroundColor(), actualElem.hasBackgroundColor());
if (expected.hasBackgroundColor()) {

View file

@ -986,8 +986,8 @@ public final class MatroskaExtractor implements Extractor {
int seconds = (int) (timeUs / 1000000);
timeUs -= (seconds * 1000000);
int milliseconds = (int) (timeUs / 1000);
timeCodeData = String.format(Locale.US, "%02d:%02d:%02d,%03d",
hours, minutes, seconds, milliseconds).getBytes();
timeCodeData = Util.getUtf8Bytes(String.format(Locale.US, "%02d:%02d:%02d,%03d", hours,
minutes, seconds, milliseconds));
}
System.arraycopy(timeCodeData, 0, subripSampleData, SUBRIP_PREFIX_END_TIMECODE_OFFSET,
SUBRIP_TIMECODE_LENGTH);

View file

@ -34,6 +34,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Calendar;
@ -238,6 +239,16 @@ public final class Util {
}
}
/**
* Returns a new byte array containing the code points of a {@link String} encoded using UTF-8.
*
* @param value The {@link String} whose bytes should be obtained.
* @return The code points encoding using UTF-8.
*/
public static byte[] getUtf8Bytes(String value) {
return value.getBytes(Charset.defaultCharset()); // UTF-8 is the default on Android.
}
/**
* Converts text to lower case using {@link Locale#US}.
*