mbonnin
12/07/2021, 2:31 PMCloseable
as a parameter, is there a nice way to indicate whether the function actually closes the Closeable
or if it's the caller responsibility? Ideally looking at the signature only?louiscad
12/07/2021, 2:59 PMuseXxx
if it closes itmbonnin
12/07/2021, 2:59 PMlouiscad
12/07/2021, 3:00 PMuseLines
mbonnin
12/07/2021, 3:00 PMJson.decodeFromStream(InputStream)
doesn't close the inputStream?louiscad
12/07/2021, 3:01 PMmbonnin
12/07/2021, 3:02 PMlouiscad
12/07/2021, 3:02 PMmbonnin
12/07/2021, 3:02 PMlouiscad
12/07/2021, 3:03 PMmbonnin
12/07/2021, 3:03 PMuseFoo()
isn't great either because it doesn't say anything about how it's going to "use" itlouiscad
12/07/2021, 3:04 PMmbonnin
12/07/2021, 3:04 PMlouiscad
12/07/2021, 3:05 PMuse { … }
when it makes sense?mbonnin
12/07/2021, 3:05 PMlouiscad
12/07/2021, 3:06 PMuse
inside no matter the naming or the signature.mbonnin
12/07/2021, 3:08 PMdecode(InputStream)
function, I want to know if I should wrap in `use {}`or not. The current way seems to rely on the documentation or just "guess" like in the Json caselouiscad
12/07/2021, 3:12 PMmbonnin
12/07/2021, 3:15 PMinputStream
after the decode
call or notUnexpected JSON token at offset 68: Expected EOF after parsing, but had { instead
JSON input: kotlinx.serialization.json.internal.ArrayAsSequence@61a002b1
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 68: Expected EOF after parsing, but had { instead
JSON input: kotlinx.serialization.json.internal.ArrayAsSequence@61a002b1
Looks like decodeFromStream
is doing yet something else 😅louiscad
12/07/2021, 3:21 PMInputStream
from <http://java.io|java.io>
?mbonnin
12/07/2021, 3:23 PMInputStream
support is pretty new IIRClouiscad
12/07/2021, 3:25 PMmbonnin
12/07/2021, 3:25 PMlouiscad
12/07/2021, 3:26 PMInputStream
an interface?mbonnin
12/07/2021, 3:26 PMlouiscad
12/07/2021, 3:27 PMmbonnin
12/07/2021, 3:27 PMlouiscad
12/07/2021, 3:28 PMmbonnin
12/07/2021, 3:28 PMlouiscad
12/07/2021, 3:28 PMmbonnin
12/07/2021, 3:28 PMlouiscad
12/07/2021, 3:29 PMmbonnin
12/07/2021, 3:29 PMthe logic to find ``` is more more simple than JSON parsing itselfIt is but if you have to parse json in all cases, you don't want to waste cpu cycles searching for bacticks at the same time
louiscad
12/07/2021, 3:30 PMmbonnin
12/07/2021, 3:30 PM@Serializable
class SimpleObject(val name: String)
@Test
fun testDecode() {
val inputStream = """
{
"name": "Object1"
}
{
"name": "Object2"
}
""".trimIndent().byteInputStream()
println("1")
println(Json.decodeFromStream<SimpleObject>(inputStream).name)
println("2")
println(Json.decodeFromStream<SimpleObject>(inputStream).name)
}
louiscad
12/07/2021, 3:31 PMmbonnin
12/07/2021, 3:32 PMlouiscad
12/07/2021, 3:32 PMfree
mbonnin
12/07/2021, 3:33 PMlouiscad
12/07/2021, 3:33 PMmbonnin
12/07/2021, 3:34 PMlouiscad
12/07/2021, 3:34 PMmbonnin
12/07/2021, 3:35 PMdecodeFromStream
to either:
• parse a complete Json stream and close it
• or allow parsing partial Json streams and leaving them openuse {}
or else leaks happens
• And at the same time it's not possible to decode partial streamslouiscad
12/07/2021, 3:37 PMhttps://c.tenor.com/ODCQZW2FncEAAAAM/sonic-hedgehog.gif▾
mbonnin
12/07/2021, 3:40 PM