Class ParsingLoadable<T>
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.ParsingLoadable<T>
-
- Type Parameters:
T
- The type of the object being loaded.
- All Implemented Interfaces:
Loader.Loadable
public final class ParsingLoadable<T> extends Object implements Loader.Loadable
ALoader.Loadable
for objects that can be parsed from binary data using aParsingLoadable.Parser
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ParsingLoadable.Parser<T>
Parses an object from loaded data.
-
Field Summary
Fields Modifier and Type Field Description DataSpec
dataSpec
TheDataSpec
that defines the data to be loaded.long
loadTaskId
Identifies the load task for this loadable.int
type
The type of the data.
-
Constructor Summary
Constructors Constructor Description ParsingLoadable(DataSource dataSource, Uri uri, int type, ParsingLoadable.Parser<? extends T> parser)
ParsingLoadable(DataSource dataSource, DataSpec dataSpec, int type, ParsingLoadable.Parser<? extends T> parser)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
bytesLoaded()
Returns the number of bytes loaded.void
cancelLoad()
Cancels the load.Map<String,List<String>>
getResponseHeaders()
Returns the response headers associated with the load.T
getResult()
Returns the loaded object, or null if an object has not been loaded.Uri
getUri()
Returns theUri
from which data was read.void
load()
Performs the load, returning on completion or cancellation.static <T> T
load(DataSource dataSource, ParsingLoadable.Parser<? extends T> parser, Uri uri, int type)
Loads a single parsable object.static <T> T
load(DataSource dataSource, ParsingLoadable.Parser<? extends T> parser, DataSpec dataSpec, int type)
Loads a single parsable object.
-
-
-
Field Detail
-
loadTaskId
public final long loadTaskId
Identifies the load task for this loadable.
-
type
public final int type
The type of the data. One of theDATA_TYPE_*
constants defined inC
. For reporting only.
-
-
Constructor Detail
-
ParsingLoadable
public ParsingLoadable(DataSource dataSource, Uri uri, int type, ParsingLoadable.Parser<? extends T> parser)
- Parameters:
dataSource
- ADataSource
to use when loading the data.uri
- TheUri
from which the object should be loaded.type
- Seetype
.parser
- Parses the object from the response.
-
ParsingLoadable
public ParsingLoadable(DataSource dataSource, DataSpec dataSpec, int type, ParsingLoadable.Parser<? extends T> parser)
- Parameters:
dataSource
- ADataSource
to use when loading the data.dataSpec
- TheDataSpec
from which the object should be loaded.type
- Seetype
.parser
- Parses the object from the response.
-
-
Method Detail
-
load
public static <T> T load(DataSource dataSource, ParsingLoadable.Parser<? extends T> parser, Uri uri, int type) throws IOException
Loads a single parsable object.- Parameters:
dataSource
- TheDataSource
through which the object should be read.parser
- TheParsingLoadable.Parser
to parse the object from the response.uri
- TheUri
of the object to read.type
- The type of the data. One of theC
DATA_TYPE_*
constants.- Returns:
- The parsed object
- Throws:
IOException
- Thrown if there is an error while loading or parsing.
-
load
public static <T> T load(DataSource dataSource, ParsingLoadable.Parser<? extends T> parser, DataSpec dataSpec, int type) throws IOException
Loads a single parsable object.- Parameters:
dataSource
- TheDataSource
through which the object should be read.parser
- TheParsingLoadable.Parser
to parse the object from the response.dataSpec
- TheDataSpec
of the object to read.type
- The type of the data. One of theC
DATA_TYPE_*
constants.- Returns:
- The parsed object
- Throws:
IOException
- Thrown if there is an error while loading or parsing.
-
getResult
@Nullable public final T getResult()
Returns the loaded object, or null if an object has not been loaded.
-
bytesLoaded
public long bytesLoaded()
Returns the number of bytes loaded. In the case that the network response was compressed, the value returned is the size of the data after decompression. Must only be called after the load completed, failed, or was canceled.
-
getUri
public Uri getUri()
Returns theUri
from which data was read. If redirection occurred, this is the redirected uri. Must only be called after the load completed, failed, or was canceled.
-
getResponseHeaders
public Map<String,List<String>> getResponseHeaders()
Returns the response headers associated with the load. Must only be called after the load completed, failed, or was canceled.
-
cancelLoad
public final void cancelLoad()
Description copied from interface:Loader.Loadable
Cancels the load.Loadable implementations should ensure that a currently executing
Loader.Loadable.load()
call will exit reasonably quickly after this method is called. TheLoader.Loadable.load()
call may exit either by returning or by throwing anIOException
.If there is a currently executing
Loader.Loadable.load()
call, then the thread on which that call is being made will be interrupted immediately after the call to this method. Hence implementations do not need to (and should not attempt to) interrupt the loading thread themselves.Although the loading thread will be interrupted, Loadable implementations should not use the interrupted status of the loading thread in
Loader.Loadable.load()
to determine whether the load has been canceled. This approach is not robust [Internal ref: b/79223737]. Instead, implementations should use their own flag to signal cancelation (for example, usingAtomicBoolean
).- Specified by:
cancelLoad
in interfaceLoader.Loadable
-
load
public final void load() throws IOException
Description copied from interface:Loader.Loadable
Performs the load, returning on completion or cancellation.- Specified by:
load
in interfaceLoader.Loadable
- Throws:
IOException
- If the input could not be loaded.
-
-