From: Niki Roo Date: Sun, 28 Apr 2019 10:14:04 +0000 (+0200) Subject: Nextable.next: blocking call X-Git-Tag: fanfix-swing-0.0.1~21^2~108 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=177e14c96d0c7318ae4a227351186735c9b5f1a6;p=fanfix-swing.git Nextable.next: blocking call --- diff --git a/src/be/nikiroo/utils/streams/NextableInputStream.java b/src/be/nikiroo/utils/streams/NextableInputStream.java index d023ad34..b8c3fe8c 100644 --- a/src/be/nikiroo/utils/streams/NextableInputStream.java +++ b/src/be/nikiroo/utils/streams/NextableInputStream.java @@ -85,6 +85,8 @@ public class NextableInputStream extends BufferedInputStream { * {@link IOException}s can happen when we have no data available in the * buffer; in that case, we fetch more data to know if we can have a next * sub-stream or not. + *

+ * This is can be a blocking call when data need to be fetched. * * @return TRUE if we unblocked the next sub-stream, FALSE if not * @@ -101,6 +103,8 @@ public class NextableInputStream extends BufferedInputStream { *

* That is, the next stream, if any, will be the last one and will not be * subject to the {@link NextableInputStreamStep}. + *

+ * This is can be a blocking call when data need to be fetched. * * @return TRUE if we unblocked the next sub-stream, FALSE if not * @@ -192,6 +196,8 @@ public class NextableInputStream extends BufferedInputStream { /** * The implementation of {@link NextableInputStream#next()} and * {@link NextableInputStream#nextAll()}. + *

+ * This is can be a blocking call when data need to be fetched. * * @param all * TRUE for {@link NextableInputStream#nextAll()}, FALSE for @@ -212,8 +218,6 @@ public class NextableInputStream extends BufferedInputStream { if (all) { step = null; } - - return true; } if (step != null && !hasMoreData() && stopped) { @@ -227,11 +231,25 @@ public class NextableInputStream extends BufferedInputStream { } checkBuffer(false); + } + + // consider that if EOF, there is no next + if (start >= stop) { + // Make sure, block if necessary + preRead(); - // consider that if EOF, there is no next return hasMoreData(); } - return false; + return true; + } + + public String DEBUG() { + String rep = String.format( + "Nextable %s: %d -> %d [eof: %s] [more data: %s]", + (stopped ? "stopped" : "running"), start, stop, "" + eof, "" + + hasMoreData()); + + return rep; } }