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
cef1f12f
authored
Jan 22, 2016
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add readString to ParsableByteArray
parent
eda8ac4e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
1 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 @
cef1f12f
...
@@ -284,6 +284,7 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -284,6 +284,7 @@ public class ParsableByteArrayTest extends TestCase {
0x00
,
0x00
,
0x00
,
(
byte
)
0xFF
0x00
,
0x00
,
0x00
,
(
byte
)
0xFF
});
});
assertEquals
(
0xFF00000000000001
L
,
byteArray
.
readLittleEndianLong
());
assertEquals
(
0xFF00000000000001
L
,
byteArray
.
readLittleEndianLong
());
assertEquals
(
8
,
byteArray
.
getPosition
());
}
}
public
void
testReadLittleEndianUnsignedInt
()
{
public
void
testReadLittleEndianUnsignedInt
()
{
...
@@ -291,6 +292,7 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -291,6 +292,7 @@ public class ParsableByteArrayTest extends TestCase {
0x10
,
0x00
,
0x00
,
(
byte
)
0xFF
0x10
,
0x00
,
0x00
,
(
byte
)
0xFF
});
});
assertEquals
(
0xFF000010
L
,
byteArray
.
readLittleEndianUnsignedInt
());
assertEquals
(
0xFF000010
L
,
byteArray
.
readLittleEndianUnsignedInt
());
assertEquals
(
4
,
byteArray
.
getPosition
());
}
}
public
void
testReadLittleEndianInt
()
{
public
void
testReadLittleEndianInt
()
{
...
@@ -298,12 +300,14 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -298,12 +300,14 @@ public class ParsableByteArrayTest extends TestCase {
0x01
,
0x00
,
0x00
,
(
byte
)
0xFF
0x01
,
0x00
,
0x00
,
(
byte
)
0xFF
});
});
assertEquals
(
0xFF000001
,
byteArray
.
readLittleEndianInt
());
assertEquals
(
0xFF000001
,
byteArray
.
readLittleEndianInt
());
assertEquals
(
4
,
byteArray
.
getPosition
());
}
}
public
void
testReadLittleEndianUnsignedInt24
()
{
public
void
testReadLittleEndianUnsignedInt24
()
{
byte
[]
data
=
{
0x01
,
0x02
,
(
byte
)
0xFF
};
byte
[]
data
=
{
0x01
,
0x02
,
(
byte
)
0xFF
};
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
data
);
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
data
);
assertEquals
(
0xFF0201
,
byteArray
.
readLittleEndianUnsignedInt24
());
assertEquals
(
0xFF0201
,
byteArray
.
readLittleEndianUnsignedInt24
());
assertEquals
(
3
,
byteArray
.
getPosition
());
}
}
public
void
testReadLittleEndianUnsignedShort
()
{
public
void
testReadLittleEndianUnsignedShort
()
{
...
@@ -311,7 +315,9 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -311,7 +315,9 @@ public class ParsableByteArrayTest extends TestCase {
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
});
});
assertEquals
(
0xFF01
,
byteArray
.
readLittleEndianUnsignedShort
());
assertEquals
(
0xFF01
,
byteArray
.
readLittleEndianUnsignedShort
());
assertEquals
(
2
,
byteArray
.
getPosition
());
assertEquals
(
0xFF02
,
byteArray
.
readLittleEndianUnsignedShort
());
assertEquals
(
0xFF02
,
byteArray
.
readLittleEndianUnsignedShort
());
assertEquals
(
4
,
byteArray
.
getPosition
());
}
}
public
void
testReadLittleEndianShort
()
{
public
void
testReadLittleEndianShort
()
{
...
@@ -319,7 +325,37 @@ public class ParsableByteArrayTest extends TestCase {
...
@@ -319,7 +325,37 @@ public class ParsableByteArrayTest extends TestCase {
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
0x01
,
(
byte
)
0xFF
,
0x02
,
(
byte
)
0xFF
});
});
assertEquals
((
short
)
0xFF01
,
byteArray
.
readLittleEndianShort
());
assertEquals
((
short
)
0xFF01
,
byteArray
.
readLittleEndianShort
());
assertEquals
(
2
,
byteArray
.
getPosition
());
assertEquals
((
short
)
0xFF02
,
byteArray
.
readLittleEndianShort
());
assertEquals
((
short
)
0xFF02
,
byteArray
.
readLittleEndianShort
());
assertEquals
(
4
,
byteArray
.
getPosition
());
}
public
void
testReadString
()
{
byte
[]
data
=
{
(
byte
)
0xC3
,
(
byte
)
0xA4
,
(
byte
)
0x20
,
(
byte
)
0xC3
,
(
byte
)
0xB6
,
(
byte
)
0x20
,
(
byte
)
0xC2
,
(
byte
)
0xAE
,
(
byte
)
0x20
,
(
byte
)
0xCF
,
(
byte
)
0x80
,
(
byte
)
0x20
,
(
byte
)
0xE2
,
(
byte
)
0x88
,
(
byte
)
0x9A
,
(
byte
)
0x20
,
(
byte
)
0xC2
,
(
byte
)
0xB1
,
(
byte
)
0x20
,
(
byte
)
0xE8
,
(
byte
)
0xB0
,
(
byte
)
0xA2
,
(
byte
)
0x20
,
};
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
data
);
assertEquals
(
"ä ö ® π √ ± 谢 "
,
byteArray
.
readString
(
data
.
length
));
assertEquals
(
data
.
length
,
byteArray
.
getPosition
());
}
public
void
testReadStringOutOfBoundsDoesNotMovePosition
()
{
byte
[]
data
=
{
(
byte
)
0xC3
,
(
byte
)
0xA4
,
(
byte
)
0x20
};
ParsableByteArray
byteArray
=
new
ParsableByteArray
(
data
);
try
{
byteArray
.
readString
(
data
.
length
+
1
);
fail
();
}
catch
(
StringIndexOutOfBoundsException
e
)
{
assertEquals
(
0
,
byteArray
.
getPosition
());
}
}
}
public
void
testReadEmptyString
()
{
public
void
testReadEmptyString
()
{
...
...
library/src/main/java/com/google/android/exoplayer/util/ParsableByteArray.java
View file @
cef1f12f
...
@@ -307,6 +307,18 @@ public final class ParsableByteArray {
...
@@ -307,6 +307,18 @@ public final class ParsableByteArray {
}
}
/**
/**
* Reads the next {@code length} bytes as UTF-8 characters.
*
* @param length the number of bytes to read.
* @return the UTF-8 {@code String} read.
*/
public
String
readString
(
int
length
)
{
String
utf8String
=
new
String
(
data
,
position
,
length
);
position
+=
length
;
return
utf8String
;
}
/**
* Reads a line of text.
* Reads a line of text.
* <p>
* <p>
* A line is considered to be terminated by any one of a carriage return ('\r'), a line feed
* A line is considered to be terminated by any one of a carriage return ('\r'), a line feed
...
@@ -346,5 +358,4 @@ public final class ParsableByteArray {
...
@@ -346,5 +358,4 @@ public final class ParsableByteArray {
return
line
;
return
line
;
}
}
}
}
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