DataSource

abstract class DataSource

A source of data.

An abstraction over the byte stream writing operations, this class allows for a flexible way to write bytes to a BufferedSink.

Generally used for specifying a data source when creating/uploading files.

  • The create method can be used for reading data from a local file.
  • The create method can be used for reading data from a byte array.
  • The create method can be used for reading data from Okio's immutable byte arrays.
  • For any other cases just extend the class and do your magic in the writeTo method.

Functions

contentLength
Link copied to clipboard
abstract fun contentLength(): Long
Return the size of the data to be written.
create
Link copied to clipboard
open fun create(data: Array<Byte>): DataSource
open fun create(file: File): DataSource
open fun create(data: ByteString): DataSource
Create a DataSource instance that reads from a byte array.
writeTo
Link copied to clipboard
abstract fun writeTo(sink: BufferedSink)
Write the data to a BufferedSink.

Properties

EMPTY
Link copied to clipboard
val EMPTY: DataSource
An empty DataSource instance.