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

jvmMain.io.ktor.util.InputJvm.kt Maven / Gradle / Ivy

/*
 * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package io.ktor.util

import kotlinx.io.core.*
import java.io.*

/**
 * Convert kotlinx.io [Input] to java [InputStream]
 */
@KtorExperimentalAPI
fun Input.asStream(): InputStream = object : InputStream() {

    override fun read(): Int = tryPeek()

    override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
        if ([email protected]) return -1
        return readAvailable(buffer, offset, length)
    }

    override fun skip(count: Long): Long = discard(count)

    override fun close() {
        [email protected]()
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy