binary-streams / loggersoft.kotlin.streams / Stream

Stream

@ExperimentalUnsignedTypes interface Stream : StreamInput, StreamOutput

Represents input and output stream.

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

Properties

defaultByteOrder

Default byte order of the stream.

abstract var defaultByteOrder: ByteOrder

defaultStringEncoding

Default string encoding of the stream.

abstract var defaultStringEncoding: StringEncoding

isReadable

Indicates that stream is readable.

abstract val isReadable: Boolean

isWritable

Indicates that stream is writable.

abstract val isWritable: Boolean

limit

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.

abstract var limit: Long

position

Current position can be changed for seekable streams.

abstract var position: Long

readBufferSize

Read buffer size in bytes for streams which support read buffering. Has negative value if buffering is not supported.

abstract var readBufferSize: Int

readTimeout

Read timeout for special streams (e.g. socket). Has negative value if timeout is not supported.

abstract var readTimeout: Int

writeBufferSize

Write buffer size in bytes for streams which support write buffering. Has negative value if buffering is not supported.

abstract var writeBufferSize: Int

writeTimeout

Write timeout for special streams (e.g. socket). Has negative value if timeout is not supported.

abstract var writeTimeout: Int

Functions

skip

Skips bytes in the stream.

open fun skip(bytes: Long): Long

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

setLimit

Sets current stream position and limit. e.g. after setLimit(10, 5) the stream position will be 10 and limit 15.

fun Stream.setLimit(position: Long, limit: Long): Unit

tryDetectBom

Tries detect BOM signature in current position and if success updates Stream.defaultByteOrder and Stream.defaultStringEncoding.

fun Stream.tryDetectBom(): Boolean

Inheritors

AbstractStream

This class is recommended as the base for any Stream implementations.

abstract class AbstractStream : Stream