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
5bfc5f37
authored
Feb 03, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Bug fixes for ByteArrayDataSource.
parent
0ef28abb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
library/src/main/java/com/google/android/exoplayer/upstream/ByteArrayDataSource.java
library/src/main/java/com/google/android/exoplayer/upstream/ByteArrayDataSource.java
View file @
5bfc5f37
...
...
@@ -27,24 +27,27 @@ public class ByteArrayDataSource implements DataSource {
private
final
byte
[]
data
;
private
int
readPosition
;
private
int
remainingBytes
;
/**
* @param data The data to be read.
*/
public
ByteArrayDataSource
(
byte
[]
data
)
{
this
.
data
=
Assertions
.
checkNotNull
(
data
);
Assertions
.
checkNotNull
(
data
);
Assertions
.
checkArgument
(
data
.
length
>
0
);
this
.
data
=
data
;
}
@Override
public
long
open
(
DataSpec
dataSpec
)
throws
IOException
{
if
(
dataSpec
.
length
==
C
.
LENGTH_UNBOUNDED
)
{
Assertions
.
checkArgument
(
dataSpec
.
position
<
data
.
length
);
}
else
{
Assertions
.
checkArgument
(
dataSpec
.
position
+
dataSpec
.
length
<=
data
.
length
);
}
readPosition
=
(
int
)
dataSpec
.
position
;
return
(
dataSpec
.
length
==
C
.
LENGTH_UNBOUNDED
)
?
(
data
.
length
-
dataSpec
.
position
)
:
dataSpec
.
length
;
remainingBytes
=
(
int
)
((
dataSpec
.
length
==
C
.
LENGTH_UNBOUNDED
)
?
(
data
.
length
-
dataSpec
.
position
)
:
dataSpec
.
length
);
if
(
remainingBytes
<=
0
||
readPosition
+
remainingBytes
>
data
.
length
)
{
throw
new
IOException
(
"Unsatisfiable range: ["
+
readPosition
+
", "
+
dataSpec
.
length
+
"], length: "
+
data
.
length
);
}
return
remainingBytes
;
}
@Override
...
...
@@ -54,8 +57,13 @@ public class ByteArrayDataSource implements DataSource {
@Override
public
int
read
(
byte
[]
buffer
,
int
offset
,
int
length
)
throws
IOException
{
if
(
remainingBytes
==
0
)
{
return
-
1
;
}
length
=
Math
.
min
(
length
,
remainingBytes
);
System
.
arraycopy
(
data
,
readPosition
,
buffer
,
offset
,
length
);
readPosition
+=
length
;
remainingBytes
-=
length
;
return
length
;
}
}
...
...
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