binary-streams / loggersoft.kotlin.streams / BitStream

BitStream

@ExperimentalUnsignedTypes class BitStream : Closeable, AutoCloseable, Flushable

Bit access over Stream.

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

Constructors

<init>

Constructs stream from StreamInput

BitStream(input: StreamInput)

Constructs stream from StreamOutput

BitStream(output: StreamOutput)

Bit access over Stream.

BitStream(stream: Stream)

Properties

bitPosition

Current absolute bit position in the stream.

var bitPosition: Long

isFixedSize

Indicates that stream has fixed size.

val isFixedSize: Boolean

isReadable

Indicates that stream is readable.

val isReadable: Boolean

isSeekable

Indicates that position of the stream can be changed.

val isSeekable: Boolean

isWritable

Indicates that stream is writable.

val isWritable: Boolean

offset

Bit offset in current byte (0..7).

var offset: Int

position

Current absolute byte position in the stream or -1 if not supported or not available at moment.

var position: Long

size

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

val size: Long

Functions

close

Closes the stream (include underlying stream as well).

fun close(): Unit

flush

Flushes write cache into underlying stream.

fun flush(): Unit

plusAssign

Writes bit as += operation.

operator fun plusAssign(value: Boolean): Unit

Writes byte as += operator.

operator fun plusAssign(value: Byte): Unit

readBigInteger

Reads arbitrary number of bits from the stream. If signed is true the last bit is interpreted as indicator of sign. Bits order is sequential that means BigEndian byte order for the integers which contain more then one byte.

fun readBigInteger(bits: Int, signed: Boolean = false): BigInteger

readBit

Reads one bit from the stream.

fun readBit(): Boolean

readBits

Reads specified bits from the stream. The bits should be in range 1..64. If signed is true the last bit is interpreted as indicator of sign. Bits order is sequential that means BigEndian byte order for the integers which contain more then one byte.

fun readBits(bits: Int, signed: Boolean = false): Long

readByte

Reads byte from the stream.

fun readByte(): Byte

readByteUnsigned

Reads byte as unsigned integer from the stream.

fun readByteUnsigned(): Int

readUBits

Reads specified bits from the stream. The bits should be in range 1..64. Bits order is sequential that means BigEndian byte order for the integers which contain more then one byte.

fun readUBits(bits: Int): ULong

skip

Skips bits in the stream.

fun skip(bits: Int): Boolean

write

Writes one bit to the stream.

fun write(value: Boolean): Unit

Writes one byte to the stream.

fun write(value: Byte): Unit

Writes bits from the Long. The bits should be in 1..64. The bits are written in natural order that means BigEndian byte order for integers which have more than one byte.

fun write(value: Long, bits: Int): Unit

Writes bits from the ULong. The bits should be in 1..64. The bits are written in natural order that means BigEndian byte order for integers which have more than one byte.

fun write(value: ULong, bits: Int): Unit

Writes arbitrary number of bits from the BigInteger. The bits are written in natural order that means BigEndian byte order for integers which have more than one byte.

fun write(value: BigInteger, bits: Int): Unit