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
941ca3f3
authored
Oct 26, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add readShort to ParsableByteArray
parent
0de2d3a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
library/src/androidTest/java/com/google/android/exoplayer/util/ParsableByteArrayTest.java
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
library/src/androidTest/java/com/google/android/exoplayer/util/ParsableByteArrayTest.java
View file @
941ca3f3
...
...
@@ -34,6 +34,31 @@ public class ParsableByteArrayTest extends TestCase {
return
testArray
;
}
public
void
testReadShort
()
{
testReadShort
((
short
)
-
1
);
testReadShort
((
short
)
0
);
testReadShort
((
short
)
1
);
testReadShort
(
Short
.
MIN_VALUE
);
testReadShort
(
Short
.
MAX_VALUE
);
}
private
static
void
testReadShort
(
short
testValue
)
{
ParsableByteArray
testArray
=
new
ParsableByteArray
(
ByteBuffer
.
allocate
(
4
).
putShort
(
testValue
).
array
());
int
readValue
=
testArray
.
readShort
();
// Assert that the value we read was the value we wrote.
assertEquals
(
testValue
,
readValue
);
// And that the position advanced as expected.
assertEquals
(
2
,
testArray
.
getPosition
());
// And that skipping back and reading gives the same results.
testArray
.
skipBytes
(-
2
);
readValue
=
testArray
.
readShort
();
assertEquals
(
testValue
,
readValue
);
assertEquals
(
2
,
testArray
.
getPosition
());
}
public
void
testReadInt
()
{
testReadInt
(
0
);
testReadInt
(
1
);
...
...
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
View file @
941ca3f3
...
...
@@ -170,6 +170,12 @@ public final class ParsableByteArray {
|
(
data
[
position
++]
&
0xFF
);
}
/** Reads the next two bytes as an signed value. */
public
short
readShort
()
{
return
(
short
)
((
data
[
position
++]
&
0xFF
)
<<
8
|
(
data
[
position
++]
&
0xFF
));
}
/** Reads the next three bytes as an unsigned value. */
public
int
readUnsignedInt24
()
{
return
(
data
[
position
++]
&
0xFF
)
<<
16
...
...
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