StreamInput

interface StreamInput : BasicStream

Represents streams for reading.

Author

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

Types

Link copied to clipboard
enum FetchHint : Enum<StreamInput.FetchHint>

Fetch hint type.

Functions

Link copied to clipboard
open fun canRead(bytes: Int): Boolean

Returns true when stream can provide bytes.

Link copied to clipboard
abstract override fun close()
Link copied to clipboard
open fun forLines(    encoding: StringEncoding = defaultStringEncoding,     byteOrder: ByteOrder = defaultByteOrder,     block: (lines: Sequence<String>) -> Unit)

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

Link copied to clipboard
abstract fun readByte(): Byte

Reads Byte from the stream.

Link copied to clipboard
abstract fun readBytes(    buffer: ByteArray,     size: Int = buffer.size,     offset: Int = 0): Int

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

Link copied to clipboard
open fun readByteUnsigned(): Int

Reads unsigned Byte from the stream.

Link copied to clipboard
open fun readChar(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder): Int

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

Link copied to clipboard
open fun readDouble(byteOrder: ByteOrder = defaultByteOrder): Double

Reads Double from the stream with specified byteOrder.

Link copied to clipboard
open fun readFloat(byteOrder: ByteOrder = defaultByteOrder): Float

Reads Float from the stream with specified byteOrder.

Link copied to clipboard
open fun readInt(byteOrder: ByteOrder = defaultByteOrder): Int

Reads Int from the stream with specified byteOrder.

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

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.

Link copied to clipboard
open fun readLine(encoding: StringEncoding = defaultStringEncoding, byteOrder: ByteOrder = defaultByteOrder): String

Reads line from the stream with specified encoding and byteOrder.

Link copied to clipboard
open fun readLong(byteOrder: ByteOrder = defaultByteOrder): Long

Reads Long from the stream with specified byteOrder.

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

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.

Link copied to clipboard
open fun readShort(byteOrder: ByteOrder = defaultByteOrder): Short

Reads Short from the stream with specified byteOrder.

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

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

Link copied to clipboard
open fun readUInt(byteOrder: ByteOrder = defaultByteOrder): UInt

Reads UInt from the stream with specified byteOrder.

Link copied to clipboard
abstract fun readULong(byteOrder: ByteOrder = defaultByteOrder): ULong

Reads ULong from the stream with specified byteOrder.

Link copied to clipboard
open fun readUShort(byteOrder: ByteOrder = defaultByteOrder): UShort

Reads UShort from the stream with specified byteOrder.

Link copied to clipboard
abstract fun skip(bytes: Long): Long

Skips bytes in the stream.

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

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

Properties

Link copied to clipboard
open val bytesAvailable: Long

Contains available bytes for read/write and the negative value if available bytes is not available at moment. Also, this property take into account limit value if it has non-negative value and isSupportLimit is true.

Link copied to clipboard
open val canFetchMore: StreamInput.FetchHint

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

Link copied to clipboard
abstract val defaultByteOrder: ByteOrder

Default byte order of the stream.

Link copied to clipboard
abstract val defaultStringEncoding: StringEncoding

Default string encoding of the stream.

Link copied to clipboard
abstract val isClosed: Boolean

Indicate that stream is closed.

Link copied to clipboard
open val isEof: Boolean

Indicates that end of stream reached.

Link copied to clipboard
abstract val isFixedSize: Boolean

Indicates that stream has fixed size.

Link copied to clipboard
abstract val isNetwork: Boolean

Indicates that stream is network based (pipe, socket etc).

Link copied to clipboard
abstract val isSeekable: Boolean

Indicates that position of the stream can be changed.

Link copied to clipboard
abstract val isSupportLimit: Boolean

Indicates that stream support validation of the limit field.

Link copied to clipboard
abstract val limit: Long

The limit position of the stream for read and write. If someone try to read or write out of this bound (position >= limit) the LimitOutOfBoundsException should be thrown.

Link copied to clipboard
abstract val position: Long

Current position in the stream. Has negative value if seek is not supported or information about current position is not available at moment.

Link copied to clipboard
abstract val size: Long

Current stream size in bytes or negative value if size isn't available at moment.

Inheritors

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extensions

Link copied to clipboard
fun StreamInput.crc16(size: Int): Int

Calculates CRC16 for size bytes in the stream.

Link copied to clipboard
fun StreamInput.crc32(size: Int): Int

Calculates CRC32 for size bytes in the stream.