1 package be
.nikiroo
.utils
.streams
;
3 import java
.io
.InputStream
;
6 * Divide an {@link InputStream} into sub-streams.
10 public class NextableInputStreamStep
{
12 private int resumeLen
;
13 private int last
= -1;
17 * Create a new divider that will separate the sub-streams each time it sees
20 * Note that the byte will be bypassed by the {@link InputStream} as far as
21 * the consumers will be aware.
24 * the byte at which to separate two sub-streams
26 public NextableInputStreamStep(int byt
) {
31 * Check if we need to stop the {@link InputStream} reading at some point in
34 * If we do, return the index at which to stop; if not, return -1.
36 * This method will <b>not</b> return the same index a second time (unless
37 * we cleared the buffer).
42 * the current position of what was read in the buffer
44 * the maximum index to use in the buffer (anything above that is
47 * @return the index at which to stop, or -1
49 public int stop(byte[] buffer
, int pos
, int len
) {
50 for (int i
= pos
; i
< len
; i
++) {
51 if (buffer
[i
] == stopAt
) {
67 * Get the maximum index to use in the buffer used in
68 * {@link NextableInputStreamStep#stop(byte[], int, int)} at resume time.
72 public int getResumeLen() {
77 * Get the number of bytes to skip at resume time.
79 * @return the number of bytes to skip
81 public int getResumeSkip() {
86 * Clear the information we may have kept about the current buffer
88 * You should call this method each time you change the content of the
89 * buffer used in {@link NextableInputStreamStep#stop(byte[], int, int)}.
91 public void clearBuffer() {