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
bbf8a9ac
authored
May 30, 2019
by
eguven
Committed by
Oliver Woodman
May 31, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Simplify CacheUtil
PiperOrigin-RevId: 250654697
parent
92e2581e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
View file @
bbf8a9ac
...
@@ -79,13 +79,7 @@ public final class CacheUtil {
...
@@ -79,13 +79,7 @@ public final class CacheUtil {
DataSpec
dataSpec
,
Cache
cache
,
@Nullable
CacheKeyFactory
cacheKeyFactory
)
{
DataSpec
dataSpec
,
Cache
cache
,
@Nullable
CacheKeyFactory
cacheKeyFactory
)
{
String
key
=
buildCacheKey
(
dataSpec
,
cacheKeyFactory
);
String
key
=
buildCacheKey
(
dataSpec
,
cacheKeyFactory
);
long
position
=
dataSpec
.
absoluteStreamPosition
;
long
position
=
dataSpec
.
absoluteStreamPosition
;
long
requestLength
;
long
requestLength
=
getRequestLength
(
dataSpec
,
cache
,
key
);
if
(
dataSpec
.
length
!=
C
.
LENGTH_UNSET
)
{
requestLength
=
dataSpec
.
length
;
}
else
{
long
contentLength
=
ContentMetadata
.
getContentLength
(
cache
.
getContentMetadata
(
key
));
requestLength
=
contentLength
==
C
.
LENGTH_UNSET
?
C
.
LENGTH_UNSET
:
contentLength
-
position
;
}
long
bytesAlreadyCached
=
0
;
long
bytesAlreadyCached
=
0
;
long
bytesLeft
=
requestLength
;
long
bytesLeft
=
requestLength
;
while
(
bytesLeft
!=
0
)
{
while
(
bytesLeft
!=
0
)
{
...
@@ -180,22 +174,19 @@ public final class CacheUtil {
...
@@ -180,22 +174,19 @@ public final class CacheUtil {
Assertions
.
checkNotNull
(
dataSource
);
Assertions
.
checkNotNull
(
dataSource
);
Assertions
.
checkNotNull
(
buffer
);
Assertions
.
checkNotNull
(
buffer
);
String
key
=
buildCacheKey
(
dataSpec
,
cacheKeyFactory
);
long
bytesLeft
;
ProgressNotifier
progressNotifier
=
null
;
ProgressNotifier
progressNotifier
=
null
;
if
(
progressListener
!=
null
)
{
if
(
progressListener
!=
null
)
{
progressNotifier
=
new
ProgressNotifier
(
progressListener
);
progressNotifier
=
new
ProgressNotifier
(
progressListener
);
Pair
<
Long
,
Long
>
lengthAndBytesAlreadyCached
=
getCached
(
dataSpec
,
cache
,
cacheKeyFactory
);
Pair
<
Long
,
Long
>
lengthAndBytesAlreadyCached
=
getCached
(
dataSpec
,
cache
,
cacheKeyFactory
);
progressNotifier
.
init
(
lengthAndBytesAlreadyCached
.
first
,
lengthAndBytesAlreadyCached
.
second
);
progressNotifier
.
init
(
lengthAndBytesAlreadyCached
.
first
,
lengthAndBytesAlreadyCached
.
second
);
bytesLeft
=
lengthAndBytesAlreadyCached
.
first
;
}
else
{
bytesLeft
=
getRequestLength
(
dataSpec
,
cache
,
key
);
}
}
String
key
=
buildCacheKey
(
dataSpec
,
cacheKeyFactory
);
long
position
=
dataSpec
.
absoluteStreamPosition
;
long
position
=
dataSpec
.
absoluteStreamPosition
;
long
bytesLeft
;
if
(
dataSpec
.
length
!=
C
.
LENGTH_UNSET
)
{
bytesLeft
=
dataSpec
.
length
;
}
else
{
long
contentLength
=
ContentMetadata
.
getContentLength
(
cache
.
getContentMetadata
(
key
));
bytesLeft
=
contentLength
==
C
.
LENGTH_UNSET
?
C
.
LENGTH_UNSET
:
contentLength
-
position
;
}
boolean
lengthUnset
=
bytesLeft
==
C
.
LENGTH_UNSET
;
boolean
lengthUnset
=
bytesLeft
==
C
.
LENGTH_UNSET
;
while
(
bytesLeft
!=
0
)
{
while
(
bytesLeft
!=
0
)
{
throwExceptionIfInterruptedOrCancelled
(
isCanceled
);
throwExceptionIfInterruptedOrCancelled
(
isCanceled
);
...
@@ -235,6 +226,17 @@ public final class CacheUtil {
...
@@ -235,6 +226,17 @@ public final class CacheUtil {
}
}
}
}
private
static
long
getRequestLength
(
DataSpec
dataSpec
,
Cache
cache
,
String
key
)
{
if
(
dataSpec
.
length
!=
C
.
LENGTH_UNSET
)
{
return
dataSpec
.
length
;
}
else
{
long
contentLength
=
ContentMetadata
.
getContentLength
(
cache
.
getContentMetadata
(
key
));
return
contentLength
==
C
.
LENGTH_UNSET
?
C
.
LENGTH_UNSET
:
contentLength
-
dataSpec
.
absoluteStreamPosition
;
}
}
/**
/**
* Reads and discards all data specified by the {@code dataSpec}.
* Reads and discards all data specified by the {@code dataSpec}.
*
*
...
...
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