All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.socket.streams.ByteArrayInputStream.kt Maven / Gradle / Ivy

There is a newer version: 0.4.8
Show newest version
package socket.streams

public class ByteArrayInputStream(private val array: UByteArray) : InputStream {

    private var position = 0

    override fun read(): UByte {
        return if (position < array.size)
            array[position++]
        else
            throw EOFException()
    }

    override fun readBytes(length: Int): UByteArray {
        try {
            val result = array.copyOfRange(position, position + length)
            position += length
            return result
        } catch (e: IndexOutOfBoundsException) {
            throw EOFException()
        }
    }

    public fun readRemaining(): UByteArray {
        return readBytes(available())
    }

    public fun available(): Int {
        return array.size - position
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy