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,
java.lang.Object trackSelectionData,
byte[] data) |
Modifier and Type | Method and Description |
---|---|
long |
bytesLoaded()
Returns the number of bytes that have been loaded.
|
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.
|
boolean |
isLoadCanceled()
Returns whether the load has been canceled.
|
void |
load()
Performs the load, returning on completion or cancellation.
|
getDurationUs
public DataChunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat, int trackSelectionReason, java.lang.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 long bytesLoaded()
Chunk
bytesLoaded
in class Chunk
public final void cancelLoad()
Loader.Loadable
public final boolean isLoadCanceled()
Loader.Loadable
public final void load() throws java.io.IOException, java.lang.InterruptedException
Loader.Loadable
java.io.IOException
java.lang.InterruptedException
protected abstract void consume(byte[] data, int limit) throws java.io.IOException
load()
. Implementations should override this method to consume the loaded
data.data
- An array containing the data.limit
- The limit of the data.java.io.IOException
- If an error occurs consuming the loaded data.