https://kotlinlang.org logo
#io
Title
# io
e

elect

10/17/2023, 12:06 PM
what am I doing wrong?
Copy code
val path = "/home/elect/IdeaProjects/scifio-lifesci/test.sdt".toPath()
println(HostFileSystem.exists(path))
println(HostFileSystem.source(path).buffer().buffer.size)
> true > 0 but test.sdt is not empty.. > -rw-rw-r-- 1 elect elect 4892652 ott 15 17:38 test.sdt I have my logic expecting a
Buffer
, that's what I understood is something I can "consume" (I need to read sequentially and sparse)
m

mbonnin

10/17/2023, 12:13 PM
You need to read
HostFileSystem.source(path).buffer()
. The following will give you everything in memory
Copy code
HostFileSystem.source(path).buffer().readUtf8()
HostFileSystem.source(path).buffer().readByteArray()
e

elect

10/17/2023, 12:14 PM
exploring right now with
BufferedSource
👍 1
m

mbonnin

10/17/2023, 12:14 PM
You can also read byte by byte:
Copy code
HostFileSystem.source(path).buffer().apply {
  readByte()
  readByte()
}
👍 1
etc...
You probably need to read in a loop:
Copy code
while(!bufferedSource.exhausted()) {
  // read stuff
}
Depends your use case
e

elect

10/17/2023, 12:17 PM
porting to MP this
👀 1
m

mbonnin

10/17/2023, 12:17 PM
If you want a good video about okio,

this video

is pretty cool
👍 1
e

elect

10/17/2023, 12:18 PM
thanks for that, I saw the three presentations suggested on the website, but this wasnt there!
m

mbonnin

10/17/2023, 12:18 PM
Ah, might be worth adding it, it's pretty cool with animated marbles and all 🙂
e

elect

10/17/2023, 12:18 PM
yep
m

mbonnin

10/17/2023, 12:18 PM
porting to MP this
Then
BufferedSource
is the perfect fit, it should have all the
readInt
,
readShort
, etc..
e

elect

10/17/2023, 12:19 PM
exactly
m

mbonnin

10/17/2023, 12:26 PM