X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FNextableInputStream.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FNextableInputStream.java;h=d023ad34482837b7896d75482d0bff85b98f9aa1;hp=4a6e0abc672abf441ef6acf51f9db9ed1d625585;hb=028ff7c29a8fb07c702ffd34913a5dd22b688211;hpb=617ad86c825bf7fdc85b72c3a453d9c90bd8f770 diff --git a/src/be/nikiroo/utils/streams/NextableInputStream.java b/src/be/nikiroo/utils/streams/NextableInputStream.java index 4a6e0ab..d023ad3 100644 --- a/src/be/nikiroo/utils/streams/NextableInputStream.java +++ b/src/be/nikiroo/utils/streams/NextableInputStream.java @@ -115,16 +115,19 @@ public class NextableInputStream extends BufferedInputStream { * Check if this stream is totally spent (no more data to read or to * process). *

- * Note: an empty stream that is still not started will return FALSE, as we - * don't know yet if it is empty. + * Note: when the stream is divided into sub-streams, each sub-stream will + * report it is eof when emptied. * * @return TRUE if it is + * + * @throws IOException + * in case of I/O error */ @Override - public boolean eof() { + public boolean eof() throws IOException { return super.eof(); } - + /** * Check if we still have some data in the buffer and, if not, fetch some. * @@ -138,7 +141,7 @@ public class NextableInputStream extends BufferedInputStream { protected boolean preRead() throws IOException { if (!stopped) { boolean bufferChanged = super.preRead(); - checkBuffer(true); + checkBuffer(bufferChanged); return bufferChanged; } @@ -172,12 +175,12 @@ public class NextableInputStream extends BufferedInputStream { * the {@link NextableInputStreamStep} */ private void checkBuffer(boolean newBuffer) { - if (step != null && stop > 0) { + if (step != null && stop >= 0) { if (newBuffer) { step.clearBuffer(); } - int stopAt = step.stop(buffer, start, stop); + int stopAt = step.stop(buffer, start, stop, eof); if (stopAt >= 0) { stop = stopAt; eof = true; @@ -216,15 +219,14 @@ public class NextableInputStream extends BufferedInputStream { if (step != null && !hasMoreData() && stopped) { stop = step.getResumeLen(); start += step.getResumeSkip(); - eof = false; + eof = step.getResumeEof(); + stopped = false; if (all) { step = null; } - if (!preRead()) { - checkBuffer(false); - } + checkBuffer(false); // consider that if EOF, there is no next return hasMoreData();