Oleh Ponomarenko12/06/2019, 2:23 PM
And then I send the bytes. I do nothing with this after. As I understand JVM garbage collector should clean this data myself after a while but does it not always. I google this, I think I can use something like try-with-resources in Java -
val bytes = fileOut.readBytes().sliceArray(range)
. But this extension is unable for the Class. Do you have some advice for me? Thanks.
karelpeeters12/06/2019, 2:26 PM
Oleh Ponomarenko12/06/2019, 2:27 PM
This method is not recommended on huge files. It has an internal limitation of 2 GB byte array size.
karelpeeters12/06/2019, 2:28 PM
Oleh Ponomarenko12/06/2019, 2:28 PM
karelpeeters12/06/2019, 2:38 PM
which is a bit more ergonomic:
val file = FileInputStream("test.txt") val data = DataInputStream(file) val result = ByteArray(100) data.readFully(result, 1000, result.size)
. Be careful about character encodings or unexpected eofs of course.
1000 until 1100
Oleh Ponomarenko12/06/2019, 2:41 PM
karelpeeters12/06/2019, 2:41 PM
Oleh Ponomarenko12/06/2019, 2:43 PM
Holger Steinhauer [Mod]12/06/2019, 4:09 PM
For example, if you’re parsing binary data and you don’t want to read the entire file at once, you must create an input stream (for binary data) or an input stream reader (for strings) - the example below will read 16 bytes:
karelpeeters12/06/2019, 4:13 PM
does not read 16 bytes, it reads up to 16 bytes.
to get where you want to be, and then repeatedly call
in a loop until you've read enough bytes. That's exactly what