binary-streams / loggersoft.kotlin.streams / ByteArea

ByteArea

open class ByteArea : ByteAreaBased, Iterable<Byte>

Represents area inside byte array buffer with specified offset and size.

Parameters

buffer - the source buffer.

size - the size of byte area.

offset - start index in buffer.

Exceptions

IllegalArgumentException - if offset is negative, size is zero or negative, buffer is empty or area is out of bounds.

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

Constructors

<init>

Constructs new ByteArray with specified size and ByteArea over it.

ByteArea(size: Int, offset: Int = 0)

Represents area inside byte array buffer with specified offset and size.

ByteArea(buffer: ByteArray, size: Int, offset: Int = 0)

Properties

boundOffset

The area upper limit.

val boundOffset: Int

buffer

the source buffer.

val buffer: ByteArray

byteArea

The object's byte area.

open val byteArea: ByteArea

offset

start index in buffer.

val offset: Int

size

the size of byte area.

val size: Int

Functions

copyTo

Copies this area to another area with specified offset within area.

fun copyTo(area: ByteArea, offset: Int = 0): ByteArray

Copies this area to buffer with specified offset within buffer.

fun copyTo(buffer: ByteArray, offset: Int): ByteArray

equals

open fun equals(other: Any?): Boolean

get

Gets Byte by index.

operator fun get(index: Int): Byte

hashCode

open fun hashCode(): Int

intersection

Returns intersection between two ByteArea over the same buffer.

fun intersection(other: ByteArea): Pair<Int, Int>?

iterator

Returns Iterator to goes through bytes of area.

open fun iterator(): Iterator<Byte>

set

Sets Byte at index.

operator fun set(index: Int, value: Byte): Unit

subarea

Returns subarea with specified size and offset.

fun subarea(size: Int, offset: Int): ByteArea

Extension Functions

crc16

Calculates CRC16 of ByteArea from offset with size starting from startValue.

fun ByteArea.crc16(startValue: Int = CRC16_START_VALUE, offset: Int = 0, size: Int = this.size - offset): Int

crc32

Calculates CRC32 of ByteArea from offset with size starting from startValue. If finalize is true returned value will be final (when data processed partially for the last block).

fun ByteArea.crc32(startValue: Int = CRC32_START_VALUE, finalize: Boolean = true, offset: Int = 0, size: Int = this.size - offset): Int