Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ea08bfd3
authored
May 11, 2020
by
olly
Committed by
Oliver Woodman
May 14, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Move isCausedByPositionOutOfRange to DataSourceException
PiperOrigin-RevId: 311002702
parent
6bf89bb4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
16 deletions
library/common/src/main/java/com/google/android/exoplayer2/upstream/DataSourceException.java
library/common/src/test/java/com/google/android/exoplayer2/upstream/DataSourceExceptionTest.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSource.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
library/common/src/main/java/com/google/android/exoplayer2/upstream/DataSourceException.java
View file @
ea08bfd3
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
androidx.annotation.Nullable
;
import
java.io.IOException
;
/**
...
...
@@ -22,6 +23,24 @@ import java.io.IOException;
*/
public
final
class
DataSourceException
extends
IOException
{
/**
* Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
* {@link #reason} is {@link #POSITION_OUT_OF_RANGE} in its cause stack.
*/
public
static
boolean
isCausedByPositionOutOfRange
(
IOException
e
)
{
@Nullable
Throwable
cause
=
e
;
while
(
cause
!=
null
)
{
if
(
cause
instanceof
DataSourceException
)
{
int
reason
=
((
DataSourceException
)
cause
).
reason
;
if
(
reason
==
DataSourceException
.
POSITION_OUT_OF_RANGE
)
{
return
true
;
}
}
cause
=
cause
.
getCause
();
}
return
false
;
}
public
static
final
int
POSITION_OUT_OF_RANGE
=
0
;
/**
...
...
library/common/src/test/java/com/google/android/exoplayer2/upstream/DataSourceExceptionTest.java
0 → 100644
View file @
ea08bfd3
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
java.io.IOException
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
/** Unit tests for {@link DataSourceException}. */
@RunWith
(
AndroidJUnit4
.
class
)
public
class
DataSourceExceptionTest
{
private
static
final
int
REASON_OTHER
=
DataSourceException
.
POSITION_OUT_OF_RANGE
-
1
;
@Test
public
void
isCausedByPositionOutOfRange_reasonIsPositionOutOfRange_returnsTrue
()
{
DataSourceException
e
=
new
DataSourceException
(
DataSourceException
.
POSITION_OUT_OF_RANGE
);
assertThat
(
DataSourceException
.
isCausedByPositionOutOfRange
(
e
)).
isTrue
();
}
@Test
public
void
isCausedByPositionOutOfRange_reasonIsOther_returnsFalse
()
{
DataSourceException
e
=
new
DataSourceException
(
REASON_OTHER
);
assertThat
(
DataSourceException
.
isCausedByPositionOutOfRange
(
e
)).
isFalse
();
}
@Test
public
void
isCausedByPositionOutOfRange_indirectauseReasonIsPositionOutOfRange_returnsTrue
()
{
DataSourceException
cause
=
new
DataSourceException
(
DataSourceException
.
POSITION_OUT_OF_RANGE
);
IOException
e
=
new
IOException
(
new
IOException
(
cause
));
assertThat
(
DataSourceException
.
isCausedByPositionOutOfRange
(
e
)).
isTrue
();
}
@Test
public
void
isCausedByPositionOutOfRange_causeReasonIsOther_returnsFalse
()
{
DataSourceException
cause
=
new
DataSourceException
(
REASON_OTHER
);
IOException
e
=
new
IOException
(
new
IOException
(
cause
));
assertThat
(
DataSourceException
.
isCausedByPositionOutOfRange
(
e
)).
isFalse
();
}
}
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSource.java
View file @
ea08bfd3
...
...
@@ -630,7 +630,7 @@ public final class CacheDataSource implements DataSource {
}
return
bytesRead
;
}
catch
(
IOException
e
)
{
if
(
currentDataSpecLengthUnset
&&
CacheUtil
.
isCausedByPositionOutOfRange
(
e
))
{
if
(
currentDataSpecLengthUnset
&&
DataSourceException
.
isCausedByPositionOutOfRange
(
e
))
{
setNoBytesRemainingAndMaybeStoreLength
();
return
C
.
RESULT_END_OF_INPUT
;
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
View file @
ea08bfd3
...
...
@@ -273,7 +273,7 @@ public final class CacheUtil {
dataSource
.
open
(
dataSpec
.
subrange
(
positionOffset
,
endOffset
-
positionOffset
));
isDataSourceOpen
=
true
;
}
catch
(
IOException
exception
)
{
if
(!
isLastBlock
||
!
isCausedByPositionOutOfRange
(
exception
))
{
if
(!
isLastBlock
||
!
DataSourceException
.
isCausedByPositionOutOfRange
(
exception
))
{
throw
exception
;
}
Util
.
closeQuietly
(
dataSource
);
...
...
@@ -349,20 +349,6 @@ public final class CacheUtil {
}
}
/* package */
static
boolean
isCausedByPositionOutOfRange
(
IOException
e
)
{
@Nullable
Throwable
cause
=
e
;
while
(
cause
!=
null
)
{
if
(
cause
instanceof
DataSourceException
)
{
int
reason
=
((
DataSourceException
)
cause
).
reason
;
if
(
reason
==
DataSourceException
.
POSITION_OUT_OF_RANGE
)
{
return
true
;
}
}
cause
=
cause
.
getCause
();
}
return
false
;
}
private
static
String
buildCacheKey
(
DataSpec
dataSpec
,
@Nullable
CacheKeyFactory
cacheKeyFactory
)
{
return
(
cacheKeyFactory
!=
null
?
cacheKeyFactory
:
CacheKeyFactory
.
DEFAULT
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment