binary-streams / loggersoft.kotlin.streams / StreamInput

StreamInput

@ExperimentalUnsignedTypes interface StreamInput : BasicStream

Represents streams for reading.

Author
Alexander Kornilov (akornilov.82@gmail.com).

Types

FetchHint

Fetch hint type.

enum class FetchHint

Properties

canFetchMore

Optional hint for fetch ability (may be useful for streams where size isn't available).

open val canFetchMore: FetchHint

Functions

canRead

Returns true when stream can provide bytes.

open fun canRead(bytes: Int): Boolean

forLines

Calls the block callback giving it a sequence of all the lines in the stream.

open fun forLines(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder, block: (lines: Sequence<String>) -> Unit): Unit

readByte

Reads Byte from the stream.

abstract fun readByte(): Byte

readBytes

Reads bytes size from the stream into the buffer starting from offset.

abstract fun readBytes(buffer: ByteArray, size: Int = buffer.size, offset: Int = 0): Int

readByteUnsigned

Reads unsigned Byte from the stream.

open fun readByteUnsigned(): Int

readChar

Reads code point from the stream with specified encoding and byteOrder.

open fun readChar(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder): Int

readDouble

Reads Double from the stream with specified byteOrder.

open fun readDouble(byteOrder: ByteOrder = defaultByteOrder): Double

readFloat

Reads Float from the stream with specified byteOrder.

open fun readFloat(byteOrder: ByteOrder = defaultByteOrder): Float

readInt

Read integer value from the stream with specified bytes count and byteOrder. If signed is true the last bit interprets as a sign. This means that if last bit is 1 the rest of the bits higher than last bit would be filled by 1. The bytes should be in range 1..8.

abstract fun readInt(bytes: Int, signed: Boolean = true, byteOrder: ByteOrder = defaultByteOrder): Long

Reads Int from the stream with specified byteOrder.

open fun readInt(byteOrder: ByteOrder = defaultByteOrder): Int

readLine

Reads line from the stream with specified encoding and byteOrder.

open fun readLine(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder): String

readLong

Read integer value from the stream as BigInteger with specified bytes count and byteOrder. If signed is true the last bit interprets as a sign.

abstract fun readLong(bytes: Int, signed: Boolean = true, byteOrder: ByteOrder = defaultByteOrder): BigInteger

Reads Long from the stream with specified byteOrder.

open fun readLong(byteOrder: ByteOrder = defaultByteOrder): Long

readShort

Reads Short from the stream with specified byteOrder.

open fun readShort(byteOrder: ByteOrder = defaultByteOrder): Short

readString

Reads string from the stream with specified encoding, byteOrder and length limit.

open fun readString(encoding: StringEncoding = defaultStringEncoding, length: Int = -1, byteOrder: ByteOrder = defaultByteOrder): String

readULong

Reads ULong from the stream with specified byteOrder.

abstract fun readULong(byteOrder: ByteOrder = defaultByteOrder): ULong

skip

Skips bytes in the stream.

abstract fun skip(bytes: Long): Long

useLines

Calls the block callback giving it a sequence of all the lines in the stream and closes it once the processing is complete.

open fun useLines(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder, block: (lines: Sequence<String>) -> Unit): Unit

Extension Functions

crc16

Calculates CRC16 for size bytes in the stream.

fun StreamInput.crc16(size: Int): Int

crc32

Calculates CRC32 for size bytes in the stream.

fun StreamInput.crc32(size: Int): Int

Inheritors

BufferedStreamInput

The decorator of StreamInput for buffering.

class BufferedStreamInput : StreamInput

ProxyStreamInput

Provides StreamInput interface from Stream.

class ProxyStreamInput : StreamInput

Stream

Represents input and output stream.

interface Stream : StreamInput, StreamOutput