+ this.in = null;
+ this.step = step;
+
+ this.buffer = in;
+ this.pos = offset;
+ this.len = length;
+
+ checkBuffer(true);
+ }
+
+ /**
+ * Return this very same {@link NextableInputStream}, but keep a counter of
+ * how many streams were open this way. When calling
+ * {@link NextableInputStream#close()}, decrease this counter if it is not
+ * already zero instead of actually closing the stream.
+ * <p>
+ * You are now responsible for it — you <b>must</b> close it.
+ * <p>
+ * This method allows you to use a wrapping stream around this one and still
+ * close the wrapping stream.
+ *
+ * @return the same stream, but you are now responsible for closing it
+ *
+ * @throws IOException
+ * in case of I/O error or if the stream is closed
+ */
+ public synchronized InputStream open() throws IOException {
+ checkClose();
+ openCounter++;
+ return this;
+ }
+
+ /**
+ * Unblock the processing of the next sub-stream.
+ * <p>
+ * It can only be called when the "current" stream is spent (i.e., you must
+ * first process the stream until it is spent).
+ * <p>
+ * We consider that when the under-laying {@link InputStream} is also spent,
+ * we cannot have a next sub-stream (it will thus return FALSE).
+ * <p>
+ * {@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.
+ *
+ * @return TRUE if we unblocked the next sub-stream, FALSE if not
+ *
+ * @throws IOException
+ * in case of I/O error or if the stream is closed
+ */
+ public boolean next() throws IOException {
+ return next(false);
+ }
+
+ /**
+ * Unblock the next sub-stream as would have done
+ * {@link NextableInputStream#next()}, but disable the sub-stream systems.
+ * <p>
+ * That is, the next stream, if any, will be the last one and will not be
+ * subject to the {@link NextableInputStreamStep}.
+ *
+ * @return TRUE if we unblocked the next sub-stream, FALSE if not
+ *
+ * @throws IOException
+ * in case of I/O error or if the stream is closed
+ */
+ public boolean nextAll() throws IOException {
+ return next(true);
+ }
+
+ public boolean startWith() {
+ // TODO