From b1fe274df39a9f964e9616f55f935fe4d309602a Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Wed, 9 Nov 2016 05:36:37 -0800 Subject: [PATCH] Replace java.text.ParseException for ExoPlayer's ParserException ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=138628300 --- .../com/google/android/exoplayer2/util/UtilTest.java | 3 +-- .../exoplayer2/source/dash/DashMediaSource.java | 10 +++------- .../source/dash/manifest/DashManifestParser.java | 7 +++---- .../java/com/google/android/exoplayer2/util/Util.java | 7 ++++--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/library/src/androidTest/java/com/google/android/exoplayer2/util/UtilTest.java b/library/src/androidTest/java/com/google/android/exoplayer2/util/UtilTest.java index e3d681d6dd..8a5a8b3d0e 100644 --- a/library/src/androidTest/java/com/google/android/exoplayer2/util/UtilTest.java +++ b/library/src/androidTest/java/com/google/android/exoplayer2/util/UtilTest.java @@ -16,7 +16,6 @@ package com.google.android.exoplayer2.util; import com.google.android.exoplayer2.testutil.TestUtil; -import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -140,7 +139,7 @@ public class UtilTest extends TestCase { assertEquals(1500L, Util.parseXsDuration("PT1.500S")); } - public void testParseXsDateTime() throws ParseException { + public void testParseXsDateTime() throws Exception { assertEquals(1403219262000L, Util.parseXsDateTime("2014-06-19T23:07:42")); assertEquals(1407322800000L, Util.parseXsDateTime("2014-08-06T11:00:00Z")); } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java index 3fde4f9c8f..e6bf8b5c02 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java @@ -314,8 +314,8 @@ public final class DashMediaSource implements MediaSource { try { long utcTimestamp = Util.parseXsDateTime(timingElement.value); onUtcTimestampResolved(utcTimestamp - manifestLoadEndTimestamp); - } catch (ParseException e) { - onUtcTimestampResolutionError(new ParserException(e)); + } catch (ParserException e) { + onUtcTimestampResolutionError(e); } } @@ -648,11 +648,7 @@ public final class DashMediaSource implements MediaSource { @Override public Long parse(Uri uri, InputStream inputStream) throws IOException { String firstLine = new BufferedReader(new InputStreamReader(inputStream)).readLine(); - try { - return Util.parseXsDateTime(firstLine); - } catch (ParseException e) { - throw new ParserException(e); - } + return Util.parseXsDateTime(firstLine); } } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java b/library/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java index 18e81e53b2..22ba50a3b6 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java @@ -38,7 +38,6 @@ import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.XmlPullParserUtil; import java.io.IOException; import java.io.InputStream; -import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -98,13 +97,13 @@ public class DashManifestParser extends DefaultHandler "inputStream does not contain a valid media presentation description"); } return parseMediaPresentationDescription(xpp, uri.toString()); - } catch (XmlPullParserException | ParseException e) { + } catch (XmlPullParserException e) { throw new ParserException(e); } } protected DashManifest parseMediaPresentationDescription(XmlPullParser xpp, - String baseUrl) throws XmlPullParserException, IOException, ParseException { + String baseUrl) throws XmlPullParserException, IOException { long availabilityStartTime = parseDateTime(xpp, "availabilityStartTime", C.TIME_UNSET); long durationMs = parseDuration(xpp, "mediaPresentationDuration", C.TIME_UNSET); long minBufferTimeMs = parseDuration(xpp, "minBufferTime", C.TIME_UNSET); @@ -815,7 +814,7 @@ public class DashManifestParser extends DefaultHandler } protected static long parseDateTime(XmlPullParser xpp, String name, long defaultValue) - throws ParseException { + throws ParserException { String value = xpp.getAttributeValue(null, name); if (value == null) { return defaultValue; diff --git a/library/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/src/main/java/com/google/android/exoplayer2/util/Util.java index 0184018bc9..c41e87d196 100644 --- a/library/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -31,6 +31,7 @@ import android.view.Display; import android.view.WindowManager; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ExoPlayerLibraryInfo; +import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; import java.io.ByteArrayOutputStream; @@ -40,7 +41,6 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.math.BigDecimal; import java.nio.charset.Charset; -import java.text.ParseException; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; @@ -433,11 +433,12 @@ public final class Util { * * @param value The attribute value to decode. * @return The parsed timestamp in milliseconds since the epoch. + * @throws ParserException if an error occurs parsing the dateTime attribute value. */ - public static long parseXsDateTime(String value) throws ParseException { + public static long parseXsDateTime(String value) throws ParserException { Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value); if (!matcher.matches()) { - throw new ParseException("Invalid date/time format: " + value, 0); + throw new ParserException("Invalid date/time format: " + value); } int timezoneShift;