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

Parses an object from loaded data.

Public constructors

ParsingLoadable(
    dataSource: DataSource!,
    dataSpec: DataSpec!,
    type: Int,
    parser: ParsingLoadable.Parser<T!>!
)
ParsingLoadable(
    dataSource: DataSource!,
    uri: Uri!,
    type: Int,
    parser: ParsingLoadable.Parser<T!>!
)

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!

Returns the Uri from which data was read.

Unit

Performs the load, returning on completion or cancellation.

java-static T!
<T> load(
    dataSource: DataSource!,
    parser: ParsingLoadable.Parser<T!>!,
    dataSpec: DataSpec!,
    type: Int
)

Loads a single parsable object.

java-static T!
<T> load(
    dataSource: DataSource!,
    parser: ParsingLoadable.Parser<T!>!,
    uri: Uri!,
    type: Int
)

Loads a single parsable object.

Public properties

DataSpec!

The DataSpec that defines the data to be loaded.

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 DataSource to use when loading the data.

dataSpec: DataSpec!

The DataSpec from which the object should be loaded.

type: Int

See type.

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 DataSource to use when loading the data.

uri: Uri!

The Uri from which the object should be loaded.

type: Int

See type.

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 ).

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 DataSource through which the object should be read.

parser: ParsingLoadable.Parser<T!>!

The Parser to parse the object from the response.

dataSpec: DataSpec!

The DataSpec of the object to read.

type: Int

The type of the data. One of the CDATA_TYPE_* constants.

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 DataSource through which the object should be read.

parser: ParsingLoadable.Parser<T!>!

The Parser to parse the object from the response.

uri: Uri!

The Uri of the object to read.

type: Int

The type of the data. One of the CDATA_TYPE_* constants.

Returns
T!

The parsed object

Throws
java.io.IOException

Thrown if there is an error while loading or parsing.

Public properties

dataSpec

val dataSpecDataSpec!

The DataSpec that defines the data to be loaded.

loadTaskId

val loadTaskIdLong

Identifies the load task for this loadable.

result

volatile val result: T?

type

val typeInt

The type of the data. One of the DATA_TYPE_* constants defined in C. For reporting only.