diff --git a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/TextServiceJvm.kt b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/TextServiceJvm.kt index 579890b0..f20e4e6f 100644 --- a/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/TextServiceJvm.kt +++ b/common/src/desktopMain/kotlin/com/artemchep/keyguard/copy/TextServiceJvm.kt @@ -3,8 +3,9 @@ package com.artemchep.keyguard.copy import com.artemchep.keyguard.common.service.text.TextService import dev.icerock.moko.resources.FileResource import org.kodein.di.DirectDI +import java.io.File import java.io.InputStream -import kotlin.io.path.Path +import java.net.URI class TextServiceJvm() : TextService { constructor( @@ -19,14 +20,14 @@ class TextServiceJvm() : TextService { .getResourceAsStream(filePath)!! override fun readFromFile(uri: String): InputStream { - when { - uri.startsWith("file://") -> { - return Path(uri) - .toFile() - .inputStream() + val parsedUri = URI.create(uri) + return when (parsedUri.scheme) { + "file" -> { + val file = parsedUri.path.let(::File) + file.inputStream() } else -> { - throw IllegalStateException("Unsupported URI protocol.") + throw IllegalStateException("Unsupported URI protocol, could not read '$uri'.") } } } diff --git a/common/src/desktopMain/kotlin/com/artemchep/keyguard/platform/LeUri.kt b/common/src/desktopMain/kotlin/com/artemchep/keyguard/platform/LeUri.kt index 5f444d7a..244f523d 100644 --- a/common/src/desktopMain/kotlin/com/artemchep/keyguard/platform/LeUri.kt +++ b/common/src/desktopMain/kotlin/com/artemchep/keyguard/platform/LeUri.kt @@ -12,4 +12,4 @@ data class LeUriImpl( actual fun leParseUri(uri: String): LeUri = LeUriImpl(uri) -actual fun leParseUri(file: File): LeUri = LeUriImpl(file.toPath().toString()) +actual fun leParseUri(file: File): LeUri = LeUriImpl(file.toURI().toString())