public interface DataSource
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
DataSource . |
long |
open(DataSpec dataSpec)
Opens the
DataSource to read the specified data. |
int |
read(byte[] buffer,
int offset,
int readLength)
Reads up to
length bytes of data and stores them into buffer , starting at
index offset . |
long open(DataSpec dataSpec) throws IOException
DataSource
to read the specified data. Calls to open(DataSpec)
and
close()
must be balanced.
Note: If open(DataSpec)
throws an IOException
, callers must still call
close()
to ensure that any partial effects of the open(DataSpec)
invocation
are cleaned up. Implementations of this class can assume that callers will call
close()
in this case.
dataSpec
- Defines the data to be read.DataSpec.length
equals C.LENGTH_UNBOUNDED
) this value
is the resolved length of the request, or C.LENGTH_UNBOUNDED
if the length is still
unresolved. For all other requests, the value returned will be equal to the request's
DataSpec.length
.IOException
- If an error occurs opening the source.void close() throws IOException
DataSource
.
Note: This method will be called even if the corresponding call to open(DataSpec)
threw an IOException
. See open(DataSpec)
for more details.
IOException
- If an error occurs closing the source.int read(byte[] buffer, int offset, int readLength) throws IOException
length
bytes of data and stores them into buffer
, starting at
index offset
.
This method blocks until at least one byte of data can be read, the end of the opened range is detected, or an exception is thrown.
buffer
- The buffer into which the read data should be stored.offset
- The start offset into buffer
at which data should be written.readLength
- The maximum number of bytes to read.C.RESULT_END_OF_INPUT
if the end of the opened
range is reached.IOException
- If an error occurs reading from the source.