Class DataSourceInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.google.android.exoplayer2.upstream.DataSourceInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class DataSourceInputStream extends InputStream
Allows data corresponding to a givenDataSpec
to be read from aDataSource
and consumed through anInputStream
.
-
-
Constructor Summary
Constructors Constructor Description DataSourceInputStream(DataSource dataSource, DataSpec dataSpec)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
bytesRead()
Returns the total number of bytes that have been read or skipped.void
close()
void
open()
Optional call to open the underlyingDataSource
.int
read()
int
read(byte[] buffer)
int
read(byte[] buffer, int offset, int length)
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
DataSourceInputStream
public DataSourceInputStream(DataSource dataSource, DataSpec dataSpec)
- Parameters:
dataSource
- TheDataSource
from which the data should be read.dataSpec
- TheDataSpec
defining the data to be read fromdataSource
.
-
-
Method Detail
-
bytesRead
public long bytesRead()
Returns the total number of bytes that have been read or skipped.
-
open
public void open() throws IOException
Optional call to open the underlyingDataSource
.Calling this method does nothing if the
DataSource
is already open. Calling this method is optional, since the read and skip methods will automatically open the underlyingDataSource
if it's not open already.- Throws:
IOException
- If an error occurs opening theDataSource
.
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] buffer) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] buffer, int offset, int length) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
-