Rob Elliot
11/24/2021, 11:44 AMBufferedReader.forEachLine
doesn’t distinguish between last line\nEOF
and last lineEOF
- in both cases the last line emitted is last line
, whether it ends in a line feed or not.
This is frustrating if you need to capture the output of the Reader
exactly, but would also like to buffer based on line feeds rather than an arbitrary number of characters.
Anyone know of a workaround?
(It’s nearly NOT KOTLIN I know, because it just delegates to `java.io.BufferedReader.readLine`… hope the fact that kotlin has extension methods calling it justifies asking?!)ephemient
11/24/2021, 12:23 PMPOSIX defines a text file as a file that contains characters organized into zero or more lines, where lines are sequences of zero or more non-newline characters plus a terminating newline charactera file that ends in a non-newline character is not a "text" file, and most line-oriented processing tools (such as
sed
) don't preserve final lines without newlines eitherRob Elliot
11/24/2021, 1:56 PMread()
directly, it was for capturing a child process’s standard out in memory while also passing it to the current process’s standard out, and I realised that for e.g. progress bars it was going to be rubbish to only emit at line feed anyway.echo 'hello world'
and printf 'hello world'
to contain the fact that the first has a newline and the second does not)ephemient
11/24/2021, 1:58 PMRob Elliot
11/24/2021, 3:09 PMephemient
11/24/2021, 3:56 PMerr: "4+0 records in\n4+0 records out\n64 bytes transferred in 0.000016 secs (3947580 bytes/sec)\n"
out: "\r\uFFFD\uFFFD8\uFFFDd\uFFFD&\uFFFD\uFFFDA\uFFFD\u0580l\uFFFD\u0000\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u0007\uFFFD`\uFFFD\uFFFDQB\u0000v\uFFFD\uFFFD\uFFFD\u491BD\uFFFD\uFFFDi\uFFFD\uFFFDe\uFFFD_\uFFFD)\uFFFD\uFFFD\u000Fy\u001C4\u0004\uFFFD\uFFFD\u0007Q\uFFFD\uFFFD#"
out: "\uFFFD"
exitCode: 0
(U+FFFD being the default replacement character)Rob Elliot
11/24/2021, 4:02 PM