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
009b454b
authored
Dec 16, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add InputStream to byte[] method to Util.
parent
7f8ddeac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
library/src/main/java/com/google/android/exoplayer/util/Util.java
library/src/main/java/com/google/android/exoplayer/util/Util.java
View file @
009b454b
...
...
@@ -107,6 +107,24 @@ public final class Util {
}
/**
* Converts the entirety of an {@link InputStream} to a byte array.
*
* @param inputStream the {@link InputStream} to be read. The input stream is not closed by this
* method.
* @return a byte array containing all of the inputStream's bytes.
* @throws IOException if an error occurs reading from the stream.
*/
public
static
byte
[]
toByteArray
(
InputStream
inputStream
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
1024
*
4
];
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
return
outputStream
.
toByteArray
();
}
/**
* Returns true if the URI is a path to a local file or a reference to a local file.
*
* @param uri The uri to test.
...
...
@@ -699,13 +717,7 @@ public final class Util {
// Read and return the response body.
InputStream
inputStream
=
urlConnection
.
getInputStream
();
try
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
byte
scratch
[]
=
new
byte
[
1024
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
scratch
))
!=
-
1
)
{
byteArrayOutputStream
.
write
(
scratch
,
0
,
bytesRead
);
}
return
byteArrayOutputStream
.
toByteArray
();
return
toByteArray
(
inputStream
);
}
finally
{
inputStream
.
close
();
}
...
...
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