Re: Making System.in interruptible, how?
On 3/8/2012 7:17 PM, Jan Burse wrote:
Arne Vajh?j schrieb:
2) BufferedReader ready will only return true if a full line
is available and not eat any characters if that is not the case
I guess that is more a freature of the underlying console,
if echo is off and the console is in line editing mode.
For example I can do the following:
abc<backspace>def
And I will get from BufferedReader abdef and not
abc<backspace>def. But there is no logic in BufferedReader
for line editing. There is only some skip LF logic
in the buffered reader.
Also the buffered reader will delegate the ready()
to the underlying stream.
Yes.
That was stated in some of what you chose not to quote.
It is not sufficient to guarantee success.
> The core logic in the code is:
>
> while (!br.ready()) {
> Thread.sleep(200);
> }
Yep, but I have a bad feeling concerning the above
logic. What if the input of the console is redirected,
and some file should be processed. Then the sleep
will throttle the input considerable.
No.
A file will b ready.
> I would seriously consider writing some JNI to do
> what is necessary on the relevant platforms.
>
> It is not portable, but at least it is obvious how it works.
Or maybe some sun.misc.* stuff. Which is a little bit
more widespread, and can be used via reflection, so
that when sun.misc.* is present interruptibility could
be provided, and otherwise the stream would not be
interruptible as before.
I would still prefer JNI.
If someone get the app on a new platform they can just
implement the C code and then it works.
If using sun.* code, then on a new platform not based
on SUN/Oracle code there is no easy fix.
Arne