Skip to content

okio / okio / BufferedSource

BufferedSource

(js, jvm, native) 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.

Properties

Name Summary
(js, jvm, native) buffer This source’s internal buffer.abstract val buffer:Buffer

Functions

Name Summary
(jvm) buffer Returns this source’s internal buffer.abstract fun ~~buffer~~():Buffer
(js, jvm, native) exhausted Returns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.abstract fun exhausted():Boolean
(js, jvm, native) indexOf Equivalent to indexOf(b, 0).abstract fun indexOf(b:Byte):Long
Returns the index of the first b in the buffer at or after fromIndex. This expands the buffer as necessary until b is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.abstract fun indexOf(b:Byte, fromIndex:Long):Long
Returns the index of b if it is found in the range of fromIndex inclusive to toIndex exclusive. If b isn’t found, or if fromIndex == toIndex, then -1 is returned.abstract fun indexOf(b:Byte, fromIndex:Long, toIndex:Long):Long
Equivalent to indexOf(bytes, 0).abstract fun indexOf(bytes:ByteString):Long
Returns the index of the first match for bytes in the buffer at or after fromIndex. This expands the buffer as necessary until bytes is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.abstract fun indexOf(bytes:ByteString, fromIndex:Long):Long
(js, jvm, native) indexOfElement Equivalent to indexOfElement(targetBytes, 0).abstract fun indexOfElement(targetBytes:ByteString):Long
Returns the first index in this buffer that is at or after fromIndex and that contains any of the bytes in targetBytes. This expands the buffer as necessary until a target byte is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.abstract fun indexOfElement(targetBytes:ByteString, fromIndex:Long):Long
(jvm) inputStream Returns an input stream that reads from this source.abstract fun inputStream():InputStream
(js, jvm, native) peek Returns a new BufferedSource that can read data from this BufferedSource without consuming it. The returned source becomes invalid once this source is next read or closed.abstract fun peek():BufferedSource
(js, jvm, native) rangeEquals Returns true if the bytes at offset in this source equal bytes. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.abstract fun rangeEquals(offset:Long, bytes:ByteString):Boolean
Returns true if byteCount bytes at offset in this source equal bytes at bytesOffset. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.abstract fun rangeEquals(offset:Long, bytes:ByteString, bytesOffset:Int, byteCount:Int):Boolean
(js, jvm, native) read Removes up to sink.length bytes from this and copies them into sink. Returns the number of bytes read, or -1 if this source is exhausted.abstract fun read(sink:ByteArray):Int
Removes up to byteCount bytes from this and copies them into sink at offset. Returns the number of bytes read, or -1 if this source is exhausted.abstract fun read(sink:ByteArray, offset:Int, byteCount:Int):Int
(js, jvm, native) readAll Removes all bytes from this and appends them to sink. Returns the total number of bytes written to sink which will be 0 if this is exhausted.abstract fun readAll(sink:Sink):Long
(js, jvm, native) readByte Removes a byte from this source and returns it.abstract fun readByte():Byte
(js, jvm, native) readByteArray Removes all bytes from this and returns them as a byte array.abstract fun readByteArray():ByteArray
Removes byteCount bytes from this and returns them as a byte array.abstract fun readByteArray(byteCount:Long):ByteArray
(js, jvm, native) readByteString Removes all bytes from this and returns them as a byte string.abstract fun readByteString():ByteString
Removes byteCount bytes from this and returns them as a byte string.abstract fun readByteString(byteCount:Long):ByteString
(js, jvm, native) readDecimalLong Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading ‘-‘). This will iterate until a non-digit character is found.abstract fun readDecimalLong():Long
(js, jvm, native) readFully Removes exactly sink.length bytes from this and copies them into sink. Throws an java.io.EOFException if the requested number of bytes cannot be read.abstract fun readFully(sink:ByteArray):Unit
Removes exactly byteCount bytes from this and appends them to sink. Throws an java.io.EOFException if the requested number of bytes cannot be read.abstract fun readFully(sink:Buffer, byteCount:Long):Unit
(js, jvm, native) readHexadecimalUnsignedLong Reads a long form this source in hexadecimal form (i.e., as a string in base 16). This will iterate until a non-hexadecimal character is found.abstract fun readHexadecimalUnsignedLong():Long
(js, jvm, native) readInt Removes four bytes from this source and returns a big-endian int.abstract fun readInt():Int
(js, jvm, native) readIntLe Removes four bytes from this source and returns a little-endian int.abstract fun readIntLe():Int
(js, jvm, native) readLong Removes eight bytes from this source and returns a big-endian long.abstract fun readLong():Long
(js, jvm, native) readLongLe Removes eight bytes from this source and returns a little-endian long.abstract fun readLongLe():Long
(js, jvm, native) readShort Removes two bytes from this source and returns a big-endian short.abstract fun readShort():Short
(js, jvm, native) readShortLe Removes two bytes from this source and returns a little-endian short.abstract fun readShortLe():Short
(jvm) readString Removes all bytes from this, decodes them as charset, and returns the string.abstract fun readString(charset:Charset):String
Removes byteCount bytes from this, decodes them as charset, and returns the string.abstract fun readString(byteCount:Long, charset:Charset):String
(js, jvm, native) readUtf8 Removes all bytes from this, decodes them as UTF-8, and returns the string. Returns the empty string if this source is empty.abstract fun readUtf8():String
Removes byteCount bytes from this, decodes them as UTF-8, and returns the string.abstract fun readUtf8(byteCount:Long):String
(js, jvm, native) readUtf8CodePoint Removes and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.abstract fun readUtf8CodePoint():Int
(js, jvm, native) readUtf8Line Removes and returns characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.abstract fun readUtf8Line():String?
(js, jvm, native) readUtf8LineStrict Removes and returns characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.abstract fun readUtf8LineStrict():String
Like readUtf8LineStrict, except this allows the caller to specify the longest allowed match. Use this to protect against streams that may not include "\n" or "\r\n".abstract fun readUtf8LineStrict(limit:Long):String
(js, jvm, native) request Returns true when the buffer contains at least byteCount bytes, expanding it as necessary. Returns false if the source is exhausted before the requested bytes can be read.abstract fun request(byteCount:Long):Boolean
(js, jvm, native) require Returns when the buffer contains at least byteCount bytes. Throws an java.io.EOFException if the source is exhausted before the required bytes can be read.abstract fun require(byteCount:Long):Unit
select (native) abstract fun select(options: <ERROR CLASS>):Int(js, jvm)
Finds the first string in options that is a prefix of this buffer, consumes it from this buffer, and returns its index. If no byte string in options is a prefix of this buffer this returns -1 and no bytes are consumed.abstract fun select(options:Options):Int
(js, jvm, native) skip Reads and discards byteCount bytes from this source. Throws an java.io.EOFException if the source is exhausted before the requested bytes can be skipped.abstract fun skip(byteCount:Long):Unit

Extension Functions

Name Summary
(jvm) gzip Returns a GzipSource that gzip-decompresses this Source while reading.funSource.gzip():GzipSource
(jvm) inflate Returns an InflaterSource that DEFLATE-decompresses this Source while reading.funSource.inflate(inflater:Inflater= Inflater()):InflaterSource

Inheritors

Name Summary
(js, jvm, native) Buffer A collection of bytes in memory.class Buffer :BufferedSource,BufferedSink