Package loggersoft.kotlin.streams

Types

Link copied to clipboard
abstract class AbstractStream : Stream

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

Link copied to clipboard
interface BasicStream : Closeable, AutoCloseable

Root interface of inheritance: contains the most generic properties of any stream.

Link copied to clipboard
interface BinaryContext

Interface for objects which has binary representation (context) and can be serialized and deserialized through binary streams.

Link copied to clipboard
class BitStream(stream: Stream) : Stream

Bit access over Stream.

Link copied to clipboard
class BufferedStreamInput(stream: StreamInput, bufferSize: Int = 4096) : StreamInput

The decorator of StreamInput for buffering.

Link copied to clipboard
class BufferedStreamOutput(stream: StreamOutput, bufferSize: Int = 4096) : StreamOutput

The decorator of StreamOutput for buffering.

Link copied to clipboard
open class ByteArea(    val buffer: ByteArray,     val size: Int,     val offset: Int = 0) : ByteAreaBased, Iterable<Byte>

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

Link copied to clipboard
interface ByteAreaBased

Represents objects which based on binary data.

Link copied to clipboard
enum ByteOrder : Enum<ByteOrder>

The byte order type.

Link copied to clipboard
class LimitOutOfBoundsException(    val position: Long,     val limit: Long,     message: String? = null) : IOException

Thrown when stream user read or write outside current limit.

Link copied to clipboard
class ProxyStreamInput(stream: Stream) : StreamInput

Provides StreamInput interface from Stream.

Link copied to clipboard
class ProxyStreamOutput(stream: Stream) : StreamOutput

Provides StreamOutput interface from Stream.

Link copied to clipboard
interface Stream : StreamInput, StreamOutput

Represents input and output stream.

Link copied to clipboard
class StreamAdapter(input: InputStream?, output: OutputStream?) : AbstractStream

Provides Stream interface from Java InputStream and OutputStream.

Link copied to clipboard
class StreamAdapterInput(input: StreamInput) : AbstractStream

Provides Stream interface from StreamInput.

Link copied to clipboard
class StreamAdapterOutput(output: StreamOutput) : AbstractStream

Provides Stream interface from StreamOutput.

Link copied to clipboard
class StreamByteArea(    data: ByteAreaBased,     readOnly: Boolean = false,     checkLimit: Boolean = false) : AbstractStream, ByteAreaBased

Implementation of the Stream for ByteArea (in fact for any ByteAreaBased objects).

Link copied to clipboard
class StreamFile(    filename: String,     readOnly: Boolean = false,     initialSize: Long = -1,     readBufferSize: Int = 0) : AbstractStream

Implementation of Stream for random access file.

Link copied to clipboard
interface StreamInput : BasicStream

Represents streams for reading.

Link copied to clipboard
interface StreamOutput : BasicStream, Flushable

Represents streams for writing.

Link copied to clipboard
enum StringEncoding : Enum<StringEncoding>

The string encoding type.

Functions

Link copied to clipboard
inline fun ByteArray.asArea(size: Int, offset: Int = 0): ByteArea

Creates ByteArea for this with specified size and offset.

Link copied to clipboard
inline fun byteBitmask(bits: Int): Byte

Returns Byte's bit mask with specified bits count. If bits negative or greater than 8 -1 will be returned.

Link copied to clipboard
inline fun ByteArray.copyFrom(    length: Int,     src: ByteArray,     offset: Int = 0,     srcOffset: Int = 0)

Copies length bytes from src byte array starting from srcOffset into this array starting from offset.

Link copied to clipboard
inline fun ByteArray.copyTo(    length: Int,     dest: ByteArray,     offset: Int = 0,     destOffset: Int = 0): ByteArray

Copies length bytes from this starting from offset into dest byte array starting from destOffset.

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

Calculates CRC16 for size bytes in the stream.

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

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

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

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

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

Calculates CRC32 for size bytes in the stream.

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

Calculates CRC32 of ByteArray 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

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).

Link copied to clipboard
inline fun ByteArray.decodeUtf8(offset: Int): Int

Decodes UTF-8 code point starting from offset.

Link copied to clipboard
inline fun String.forCodePoints(    startIndex: Int = 0,     size: Int = -1,     block: (index: Int, ch1: Char, ch2: Char, codePoint: Int, isSurrogate: Boolean) -> Boolean): Int

Goes through this code points starting from startIndex and with size limit.

Link copied to clipboard
inline fun ByteArray.hasUtf8At(offset: Int): Int

Returns bytes count of UTF-8 code point at offset or -1 if the valid code point wasn't found in that position.

Link copied to clipboard
fun intBitmask(bits: Int): Int

Returns Int's bit mask with specified bits count. If bits negative or greater than 32 -1 will be returned.

Link copied to clipboard
inline fun Byte.isBitmask(mask: Int): Boolean

Returns true when all bits in the mask are set (1).

Link copied to clipboard
inline fun Int.isCodePointAscii(): Boolean

Returns true if this code point is the valid ASCII character.

Link copied to clipboard
fun String.lengthBytes(    encoding: StringEncoding = StringEncoding.UTF8,     startIndex: Int = 0,     size: Int = -1,     needTerminator: Boolean = true): Int

Calculates bytes required to store this string in specified encoding starting from startIndex and with size limit. If needTerminator is true also place for the last zero character will be counted too.

Link copied to clipboard
fun longBitmask(bits: Int): Long

Returns Long's bit mask with specified bits count. If bits negative or greater than 64 -1 will be returned.

Link copied to clipboard
inline fun <E> numberToBytes(    value: E,     bytes: Int,     byteOrder: ByteOrder = nativeByteOrder,     receiver: (index: Int, byte: Byte) -> Unit,     doShr: (value: E, shift: Int) -> Byte)

Writes value as bytes to receiver with specified byteOrder.

Link copied to clipboard
inline fun File.openBinaryStream(    readOnly: Boolean = true,     encoding: StringEncoding = StringEncoding.UTF8,     byteOrder: ByteOrder = nativeByteOrder,     readBufferSize: Int = 4096,     writeBufferSize: Int = 0): AbstractStream

Opens random access file stream from Java File.

Link copied to clipboard
inline fun Stream.setLimit(position: Long, limit: Long)

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

Link copied to clipboard
fun ByteArray.toBigInteger(    bytes: Int,     signed: Boolean = true,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0): BigInteger

Extracts BigInteger value from this byte array starting from offset with specified bytes count and byteOrder. If signed is true the last bit interprets as a sign.

Link copied to clipboard
inline fun Long.toBigIntegerUnsigned(): BigInteger

Returns unsigned representation of this value as BigInteger.

Link copied to clipboard
inline fun InputStream.toBinaryBufferedStream(    bufferSize: Int = 4096,     encoding: StringEncoding = StringEncoding.UTF8,     byteOrder: ByteOrder = nativeByteOrder): StreamInput

Creates StreamInput from Java I/O InputStream with BufferedStreamInput.

inline fun OutputStream.toBinaryBufferedStream(    bufferSize: Int = 4096,     encoding: StringEncoding = StringEncoding.UTF8,     byteOrder: ByteOrder = nativeByteOrder): StreamOutput

Creates StreamOutput from Java I/O OutputStream with BufferedStreamOutput.

Link copied to clipboard
inline fun InputStream.toBinaryStream(encoding: StringEncoding = StringEncoding.UTF8, byteOrder: ByteOrder = nativeByteOrder): StreamInput

Creates StreamInput from Java I/O InputStream.

inline fun OutputStream.toBinaryStream(encoding: StringEncoding = StringEncoding.UTF8, byteOrder: ByteOrder = nativeByteOrder): StreamOutput

Creates StreamOutput from Java I/O OutputStream.

Link copied to clipboard
inline fun BigInteger.toBytes(    bytes: Int,     byteOrder: ByteOrder = nativeByteOrder,     receiver: (index: Int, byte: Byte) -> Unit)

Writes this value as bytes to receiver with specified byteOrder.

inline fun Long.toBytes(    bytes: Int = Long.SIZE_BYTES,     byteOrder: ByteOrder = nativeByteOrder,     receiver: (index: Int, byte: Byte) -> Unit)

Writes this value as bytes to receiver with specified byteOrder.

inline fun ULong.toBytes(    bytes: Int = ULong.SIZE_BYTES,     byteOrder: ByteOrder = nativeByteOrder,     receiver: (index: Int, byte: Byte) -> Unit)

Writes this value as bytes to receiver with specified byteOrder.

inline fun BigInteger.toBytes(    buffer: ByteArray,     bytes: Int,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0)

Writes this value as bytes to buffer byte array starting from offset with specified byteOrder.

inline fun Long.toBytes(    buffer: ByteArray,     bytes: Int = 8,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0)

Writes this value as bytes to buffer byte array starting from offset with specified byteOrder.

inline fun ULong.toBytes(    buffer: ByteArray,     bytes: Int = 8,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0)

Writes this value as bytes to buffer byte array starting from offset with specified byteOrder.

Link copied to clipboard
inline fun ByteArray.toInteger(    bytes: Int = 8,     signed: Boolean = true,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0): Long

Extracts Long value from this byte array starting from offset 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
inline fun Byte.toIntUnsigned(): Int

Returns unsigned representation of this.

Link copied to clipboard
inline fun ByteArray.toUnsigned(    bytes: Int = ULong.SIZE_BYTES,     byteOrder: ByteOrder = nativeByteOrder,     offset: Int = 0): ULong

Extracts ULong value from this byte array starting from offset with specified bytes count and byteOrder. The bytes should be in range 1..8.

Link copied to clipboard
inline fun Int.toUtf8(buffer: ByteArray, offset: Int = 0): Int

Encodes this code point to UTF-8 and writes result into buffer starting from offset.

Link copied to clipboard
fun Stream.tryDetectBom(): Boolean

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

Link copied to clipboard
inline fun Byte.utf8Len(): Int

Returns total bytes count in the UTF-8 code point by fist this.

Link copied to clipboard
inline fun Int.utf8Size(): Int

Returns a number of bytes required to represent this code point in UTF-8 or -1 for invalid code point.

Link copied to clipboard
inline fun validateUtf8Size(size: Int): Int

Validates the size of UTF-8 code point in bytes and if it is invalid throws CharacterCodingException.

Properties

Link copied to clipboard
const val BOM: Int = 65279

The code point of BOM character.

Link copied to clipboard
const val CRC16_START_VALUE: Int = 0

Default start value for CRC16.

Link copied to clipboard
const val CRC32_START_VALUE: Int

Default start value for CRC32.

Link copied to clipboard
const val EOL: Int = 10

The code point of an end-of-line character.

Link copied to clipboard
val eolSkipChars: Set<Int>

The immutable set of extra end-of-line characters for ignoring.

Link copied to clipboard
const val MaxUtf8CodePointSize: Int = 4

Maximum bytes count for any code point in UTF-8 encoding.

Link copied to clipboard
val nativeByteOrder: ByteOrder

Current byte order for the native architecture.