import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
/**
* This {@link InputStream} can be separated into sub-streams (you can process
* {@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.
+ * <p>
+ * 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
*
* <p>
* That is, the next stream, if any, will be the last one and will not be
* subject to the {@link NextableInputStreamStep}.
+ * <p>
+ * 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
*
/**
* The implementation of {@link NextableInputStream#next()} and
* {@link NextableInputStream#nextAll()}.
+ * <p>
+ * This is can be a blocking call when data need to be fetched.
*
* @param all
* TRUE for {@link NextableInputStream#nextAll()}, FALSE for
if (all) {
step = null;
}
-
- return true;
}
if (step != null && !hasMoreData() && stopped) {
}
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 data = "";
+ if (stop > 0) {
+ try {
+ data = new String(Arrays.copyOfRange(buffer, 0, stop), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ }
+ if (data.length() > 50) {
+ data = data.substring(0, 47) + "...";
+ }
+ }
+ String rep = String.format(
+ "Nextable %s: %d -> %d [eof: %s] [more data: %s]: %s",
+ (stopped ? "stopped" : "running"), start, stop, "" + eof, ""
+ + hasMoreData(), data);
+
+ return rep;
}
}