binary-streams / loggersoft.kotlin.streams / StreamFile

StreamFile

@ExperimentalUnsignedTypes class StreamFile : AbstractStream

Implementation of Stream for random access file.

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

Constructors

<init>

Constructs file stream from File.

StreamFile(file: File, readOnly: Boolean = false, initialSize: Long = -1, readBufferSize: Int = 0)

Implementation of Stream for random access file.

StreamFile(filename: String, readOnly: Boolean = false, initialSize: Long = -1, readBufferSize: Int = 0)

Properties

isFixedSize

val isFixedSize: Boolean

isReadable

Indicates that stream is readable.

val isReadable: Boolean

isSeekable

val isSeekable: Boolean

isSupportLimit

val isSupportLimit: Boolean

isWritable

Indicates that stream is writable.

val isWritable: Boolean

position

Current position can be changed for seekable streams.

var position: Long

readBufferSize

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

var readBufferSize: Int

size

val size: Long

writeBufferSize

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

var writeBufferSize: Int

Functions

close

fun close(): Unit

flush

fun flush(): Unit

readByte

Reads Byte from the stream.

fun readByte(): Byte

readBytes

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

fun readBytes(buffer: ByteArray, size: Int, offset: Int): Int

readInt

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.

fun readInt(bytes: Int, signed: Boolean, byteOrder: ByteOrder): Long

readLong

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.

fun readLong(bytes: Int, signed: Boolean, byteOrder: ByteOrder): BigInteger

readULong

Reads ULong from the stream with specified byteOrder.

fun readULong(byteOrder: ByteOrder): ULong

writeByte

Writes Byte into the stream.

fun writeByte(value: Byte): Unit

writeBytes

Writes size bytes of buffer starting from offset into the stream.

fun writeBytes(buffer: ByteArray, size: Int, offset: Int): Unit

writeInt

Writes value with size in bytes with specified byteOrder into the stream. The bytes should be in 1..8 range.

fun writeInt(value: Long, bytes: Int, byteOrder: ByteOrder): Unit

writeLong

Writes value with size in bytes with specified byteOrder into the stream.

fun writeLong(value: BigInteger, bytes: Int, byteOrder: ByteOrder): Unit

writeULong

Writes ULong with specified byteOrder into the stream.

fun writeULong(value: ULong, byteOrder: ByteOrder): Unit

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