Skip to content

2.x API

okio / okio

Package okio

Types

Name Summary
AsyncTimeout
(JVM)
open class AsyncTimeout :Timeout
This timeout uses a background thread to take action exactly when the timeout occurs. Use this to implement timeouts where they aren’t supported natively, such as to sockets that are blocked on writing.
Buffer
(JVM, js, native)
expect class Buffer :BufferedSource,BufferedSink
A collection of bytes in memory.
BufferedSink
(JVM, js, native)
expect interface BufferedSink :Sink
A sink that keeps a buffer internally so that callers can do small writes without a performance penalty.
BufferedSource
(JVM, js, native)
expect interface BufferedSource :Source
A source that keeps a buffer internally so that callers can do small reads without a performance penalty. It also allows clients to read ahead, buffering as much as necessary before consuming input.
ByteString
(JVM, js, native)
open expect class ByteString :Comparable<ByteString>
An immutable sequence of bytes.
DeflaterSink
(JVM)
class DeflaterSink :Sink
A sink that uses DEFLATE to compress data written to another source.
ForwardingSink
(JVM)
abstract class ForwardingSink :Sink
A Sink which forwards calls to another. Useful for subclassing.
ForwardingSource
(JVM)
abstract class ForwardingSource :Source
A Source which forwards calls to another. Useful for subclassing.
ForwardingTimeout
(JVM)
open class ForwardingTimeout :Timeout
A Timeout which forwards calls to another. Useful for subclassing.
GzipSink
(JVM)
class GzipSink :Sink
A sink that uses GZIP to compress written data to another sink.
GzipSource
(JVM)
class GzipSource :Source
A source that uses GZIP to decompress data read from another source.
HashingSink
(JVM)
class HashingSink :ForwardingSink
A sink that computes a hash of the full stream of bytes it has accepted. To use, create an instance with your preferred hash algorithm. Write all of the data to the sink and then call hash to compute the final hash value.
HashingSource
(JVM)
class HashingSource :ForwardingSource
A source that computes a hash of the full stream of bytes it has supplied. To use, create an instance with your preferred hash algorithm. Exhaust the source by reading all of its bytes and then call hash to compute the final hash value.
InflaterSource
(JVM)
class InflaterSource :Source
A source that uses DEFLATE to decompress data read from another source.
Options class Options
An indexed set of values that may be read with BufferedSource.select.
Pipe
(JVM)
class Pipe
A source and a sink that are attached. The sink’s output is the source’s input. Typically each is accessed by its own thread: a producer thread writes data to the sink and a consumer thread reads data from the source.
Sink
(JVM, js, native)
expect interface Sink
Receives a stream of bytes. Use this interface to write data wherever it’s needed: to the network, storage, or a buffer in memory. Sinks may be layered to transform received data, such as to compress, encrypt, throttle, or add protocol framing.
Source
(JVM, js, native)
expect interface Source
Supplies a stream of bytes. Use this interface to read data from wherever it’s located: from the network, storage, or a buffer in memory. Sources may be layered to transform supplied data, such as to decompress, decrypt, or remove protocol framing.
Throttler
(JVM)
class Throttler
Enables limiting of Source and Sink throughput. Attach to this throttler via source and sink and set the desired throughput via bytesPerSecond. Multiple Sources and Sinks can be attached to a single Throttler and they will be throttled as a group, where their combined throughput will not exceed the desired throughput. The same Source or Sink can be attached to multiple Throttlers and its throughput will not exceed the desired throughput of any of the Throttlers.
Timeout
(JVM, js, native)
open expect class Timeout
A policy on how much time to spend on a task before giving up. When a task times out, it is left in an unspecified state and should be abandoned. For example, if reading from a source times out, that source should be closed and the read should be retried later. If writing to a sink times out, the same rules apply: close the sink and retry later.

Exceptions

Name Summary
ArrayIndexOutOfBoundsException
(JVM, js, native)
expect class ArrayIndexOutOfBoundsException :IndexOutOfBoundsException
EOFException
(JVM, js, native)
open expect class EOFException :IOException
IOException
(JVM, js, native)
open expect class IOException :Exception

Extensions for External Classes

Name Summary
java.io.File
java.io.InputStream
java.io.OutputStream
java.net.Socket
java.nio.file.Path
kotlin.String

Properties

Name Summary
Okio
(JVM)
val Okio: -DeprecatedOkio
Utf8
(JVM)
val Utf8: -DeprecatedUtf8

Functions

Name Summary
blackholeSink
(JVM, js, native)
expect fun blackholeSink():Sink
Returns a sink that writes nowhere.
buffer
(JVM, js, native)
expect funSource.buffer():BufferedSource
Returns a new source that buffers reads from source. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get an ergonomic and efficient access to data.expect funSink.buffer():BufferedSink
Returns a new sink that buffers writes to sink. The returned sink will batch writes to sink. Use this wherever you write to a sink to get an ergonomic and efficient access to data.
deflate
(JVM)
funSink.deflate(deflater:Deflater= Deflater()):DeflaterSink
Returns an DeflaterSink that DEFLATE-compresses data to this Sink while writing.
gzip
(JVM)
funSink.gzip():GzipSink
Returns a GzipSink that gzip-compresses to this Sink while writing.funSource.gzip():GzipSource
Returns a GzipSource that gzip-decompresses this Source while reading.
inflate
(JVM)
funSource.inflate(inflater:Inflater= Inflater()):InflaterSource
Returns an InflaterSource that DEFLATE-decompresses this Source while reading.