public abstract class DataChunk extends Chunk
Chunk
implementations where the data should be loaded into a
byte[]
before being consumed.dataSource, dataSpec, endTimeUs, startTimeUs, trackFormat, trackSelectionData, trackSelectionReason, type
Constructor and Description |
---|
DataChunk(DataSource dataSource,
DataSpec dataSpec,
int type,
Format trackFormat,
int trackSelectionReason,
Object trackSelectionData,
byte[] data) |
Modifier and Type | Method and Description |
---|---|
void |
cancelLoad()
Cancels the load.
|
protected abstract void |
consume(byte[] data,
int limit)
Called by
load() . |
byte[] |
getDataHolder()
Returns the array in which the data is held.
|
void |
load()
Performs the load, returning on completion or cancellation.
|
bytesLoaded, getDurationUs, getResponseHeaders, getUri
public DataChunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat, int trackSelectionReason, Object trackSelectionData, byte[] data)
dataSource
- The source from which the data should be loaded.dataSpec
- Defines the data to be loaded.type
- See Chunk.type
.trackFormat
- See Chunk.trackFormat
.trackSelectionReason
- See Chunk.trackSelectionReason
.trackSelectionData
- See Chunk.trackSelectionData
.data
- An optional recycled array that can be used as a holder for the data.public byte[] getDataHolder()
This method should be used for recycling the holder only, and not for reading the data.
public final void cancelLoad()
Loader.Loadable
public final void load() throws IOException, InterruptedException
Loader.Loadable
IOException
- If the input could not be loaded.InterruptedException
- If the thread was interrupted.protected abstract void consume(byte[] data, int limit) throws IOException
load()
. Implementations should override this method to consume the loaded
data.data
- An array containing the data.limit
- The limit of the data.IOException
- If an error occurs consuming the loaded data.