ParsingLoadable
@UnstableApi
class ParsingLoadable<T> : Loader.Loadable
A Loadable for objects that can be parsed from binary data using a Parser.
| Parameters | |
|---|---|
<T> |
The type of the object being loaded. |
Summary
Nested types |
|---|
interface ParsingLoadable.Parser<T>Parses an object from loaded data. |
Public constructors |
|---|
ParsingLoadable( |
ParsingLoadable( |
Public functions |
|
|---|---|
Long |
Returns the number of bytes loaded. |
Unit |
Cancels the load. |
(Mutable)Map<String!, (Mutable)List<String!>!>! |
Returns the response headers associated with the load. |
Uri! |
getUri()Returns the |
Unit |
load()Performs the load, returning on completion or cancellation. |
java-static T! |
<T> load(Loads a single parsable object. |
java-static T! |
<T> load(Loads a single parsable object. |
Public properties |
|
|---|---|
DataSpec! |
The |
Long |
Identifies the load task for this loadable. |
volatile T? |
|
Int |
The type of the data. |
Public constructors
ParsingLoadable
ParsingLoadable(
dataSource: DataSource!,
dataSpec: DataSpec!,
type: Int,
parser: ParsingLoadable.Parser<T!>!
)
| Parameters | |
|---|---|
dataSource: DataSource! |
A |
dataSpec: DataSpec! |
The |
type: Int |
See |
parser: ParsingLoadable.Parser<T!>! |
Parses the object from the response. |
ParsingLoadable
ParsingLoadable(
dataSource: DataSource!,
uri: Uri!,
type: Int,
parser: ParsingLoadable.Parser<T!>!
)
| Parameters | |
|---|---|
dataSource: DataSource! |
A |
uri: Uri! |
The |
type: Int |
See |
parser: ParsingLoadable.Parser<T!>! |
Parses the object from the response. |
Public functions
bytesLoaded
fun bytesLoaded(): Long
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.
cancelLoad
fun cancelLoad(): Unit
Cancels the load.
Loadable implementations should ensure that a currently executing load call will exit reasonably quickly after this method is called. The load call may exit either by returning or by throwing an IOException.
If there is a currently executing 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 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, using AtomicBoolean).
getResponseHeaders
fun getResponseHeaders(): (Mutable)Map<String!, (Mutable)List<String!>!>!
Returns the response headers associated with the load. Must only be called after the load completed, failed, or was canceled.
getUri
fun getUri(): Uri!
Returns the Uri 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.
load
fun load(): Unit
Performs the load, returning on completion or cancellation.
| Throws | |
|---|---|
java.io.IOException |
If the input could not be loaded. |
load
java-static fun <T> load(
dataSource: DataSource!,
parser: ParsingLoadable.Parser<T!>!,
dataSpec: DataSpec!,
type: Int
): T!
Loads a single parsable object.
| Parameters | |
|---|---|
dataSource: DataSource! |
The |
parser: ParsingLoadable.Parser<T!>! |
The |
dataSpec: DataSpec! |
The |
type: Int |
The type of the data. One of the |
| Returns | |
|---|---|
T! |
The parsed object |
| Throws | |
|---|---|
java.io.IOException |
Thrown if there is an error while loading or parsing. |
load
java-static fun <T> load(
dataSource: DataSource!,
parser: ParsingLoadable.Parser<T!>!,
uri: Uri!,
type: Int
): T!
Loads a single parsable object.
| Parameters | |
|---|---|
dataSource: DataSource! |
The |
parser: ParsingLoadable.Parser<T!>! |
The |
uri: Uri! |
The |
type: Int |
The type of the data. One of the |
| Returns | |
|---|---|
T! |
The parsed object |
| Throws | |
|---|---|
java.io.IOException |
Thrown if there is an error while loading or parsing. |