Browse Source

[resources] Properly close input stream when read resource bytes.

pull/5006/head
Konstantin Tskhovrebov 5 months ago
parent
commit
be4dfa4543
  1. 2
      components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt
  2. 2
      components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt

2
components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/ResourceReader.android.kt

@ -18,7 +18,7 @@ internal actual fun getPlatformResourceReader(): ResourceReader = object : Resou
override suspend fun read(path: String): ByteArray { override suspend fun read(path: String): ByteArray {
val resource = getResourceAsStream(path) val resource = getResourceAsStream(path)
return resource.readBytes() return resource.use { input -> input.readBytes() }
} }
override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray { override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray {

2
components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceReader.desktop.kt

@ -5,7 +5,7 @@ import java.io.InputStream
internal actual fun getPlatformResourceReader(): ResourceReader = object : ResourceReader { internal actual fun getPlatformResourceReader(): ResourceReader = object : ResourceReader {
override suspend fun read(path: String): ByteArray { override suspend fun read(path: String): ByteArray {
val resource = getResourceAsStream(path) val resource = getResourceAsStream(path)
return resource.readBytes() return resource.use { input -> input.readBytes() }
} }
override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray { override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray {

Loading…
Cancel
Save