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
787cfb94
authored
Jul 22, 2020
by
bachinger
Committed by
Oliver Woodman
Jul 24, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Enable nullness checking for CacheDataSink
PiperOrigin-RevId: 322575337
parent
d33ba74a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java
View file @
787cfb94
...
...
@@ -15,6 +15,9 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.upstream.DataSink
;
...
...
@@ -99,7 +102,7 @@ public final class CacheDataSink implements DataSink {
@Override
public
DataSink
createDataSink
()
{
return
new
CacheDataSink
(
Assertions
.
checkNotNull
(
cache
),
fragmentSize
,
bufferSize
);
return
new
CacheDataSink
(
checkNotNull
(
cache
),
fragmentSize
,
bufferSize
);
}
}
...
...
@@ -166,13 +169,14 @@ public final class CacheDataSink implements DataSink {
+
MIN_RECOMMENDED_FRAGMENT_SIZE
+
". This may cause poor cache performance."
);
}
this
.
cache
=
Assertions
.
checkNotNull
(
cache
);
this
.
cache
=
checkNotNull
(
cache
);
this
.
fragmentSize
=
fragmentSize
==
C
.
LENGTH_UNSET
?
Long
.
MAX_VALUE
:
fragmentSize
;
this
.
bufferSize
=
bufferSize
;
}
@Override
public
void
open
(
DataSpec
dataSpec
)
throws
CacheDataSinkException
{
checkNotNull
(
dataSpec
.
key
);
if
(
dataSpec
.
length
==
C
.
LENGTH_UNSET
&&
dataSpec
.
isFlagSet
(
DataSpec
.
FLAG_DONT_CACHE_IF_LENGTH_UNKNOWN
))
{
this
.
dataSpec
=
null
;
...
...
@@ -183,7 +187,7 @@ public final class CacheDataSink implements DataSink {
dataSpec
.
isFlagSet
(
DataSpec
.
FLAG_ALLOW_CACHE_FRAGMENTATION
)
?
fragmentSize
:
Long
.
MAX_VALUE
;
dataSpecBytesWritten
=
0
;
try
{
openNextOutputStream
();
openNextOutputStream
(
dataSpec
);
}
catch
(
IOException
e
)
{
throw
new
CacheDataSinkException
(
e
);
}
...
...
@@ -191,6 +195,7 @@ public final class CacheDataSink implements DataSink {
@Override
public
void
write
(
byte
[]
buffer
,
int
offset
,
int
length
)
throws
CacheDataSinkException
{
@Nullable
DataSpec
dataSpec
=
this
.
dataSpec
;
if
(
dataSpec
==
null
)
{
return
;
}
...
...
@@ -199,11 +204,11 @@ public final class CacheDataSink implements DataSink {
while
(
bytesWritten
<
length
)
{
if
(
outputStreamBytesWritten
==
dataSpecFragmentSize
)
{
closeCurrentOutputStream
();
openNextOutputStream
();
openNextOutputStream
(
dataSpec
);
}
int
bytesToWrite
=
(
int
)
Math
.
min
(
length
-
bytesWritten
,
dataSpecFragmentSize
-
outputStreamBytesWritten
);
outputStream
.
write
(
buffer
,
offset
+
bytesWritten
,
bytesToWrite
);
castNonNull
(
outputStream
)
.
write
(
buffer
,
offset
+
bytesWritten
,
bytesToWrite
);
bytesWritten
+=
bytesToWrite
;
outputStreamBytesWritten
+=
bytesToWrite
;
dataSpecBytesWritten
+=
bytesToWrite
;
...
...
@@ -225,12 +230,14 @@ public final class CacheDataSink implements DataSink {
}
}
private
void
openNextOutputStream
()
throws
IOException
{
private
void
openNextOutputStream
(
DataSpec
dataSpec
)
throws
IOException
{
long
length
=
dataSpec
.
length
==
C
.
LENGTH_UNSET
?
C
.
LENGTH_UNSET
:
Math
.
min
(
dataSpec
.
length
-
dataSpecBytesWritten
,
dataSpecFragmentSize
);
file
=
cache
.
startFile
(
dataSpec
.
key
,
dataSpec
.
position
+
dataSpecBytesWritten
,
length
);
file
=
cache
.
startFile
(
castNonNull
(
dataSpec
.
key
),
dataSpec
.
position
+
dataSpecBytesWritten
,
length
);
FileOutputStream
underlyingFileOutputStream
=
new
FileOutputStream
(
file
);
if
(
bufferSize
>
0
)
{
if
(
bufferedOutputStream
==
null
)
{
...
...
@@ -258,7 +265,7 @@ public final class CacheDataSink implements DataSink {
}
finally
{
Util
.
closeQuietly
(
outputStream
);
outputStream
=
null
;
File
fileToCommit
=
file
;
File
fileToCommit
=
castNonNull
(
file
)
;
file
=
null
;
if
(
success
)
{
cache
.
commitFile
(
fileToCommit
,
outputStreamBytesWritten
);
...
...
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