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 last
= -1;
13 private int resumeLen
;
14 private int resumeSkip
;
15 private boolean resumeEof
;
18 * Create a new divider that will separate the sub-streams each time it sees
21 * Note that the byte will be bypassed by the {@link InputStream} as far as
22 * the consumers will be aware.
25 * the byte at which to separate two sub-streams
27 public NextableInputStreamStep(int byt
) {
32 * Check if we need to stop the {@link InputStream} reading at some point in
35 * If we do, return the index at which to stop; if not, return -1.
37 * This method will <b>not</b> return the same index a second time (unless
38 * we cleared the buffer).
43 * the current position of what was read in the buffer
45 * the maximum index to use in the buffer (anything above that is
48 * the current state of the under-laying stream
50 * @return the index at which to stop, or -1
52 public int stop(byte[] buffer
, int pos
, int len
, boolean eof
) {
53 for (int i
= pos
; i
< len
; i
++) {
54 if (buffer
[i
] == stopAt
) {
71 * Get the maximum index to use in the buffer used in
72 * {@link NextableInputStreamStep#stop(byte[], int, int, boolean)} at resume
77 public int getResumeLen() {
82 * Get the number of bytes to skip at resume time.
84 * @return the number of bytes to skip
86 public int getResumeSkip() {
91 * Get the under-laying stream state at resume time.
93 * @return the EOF state
95 public boolean getResumeEof() {
100 * Clear the information we may have kept about the current buffer
102 * You should call this method each time you change the content of the
104 * {@link NextableInputStreamStep#stop(byte[], int, int, boolean)}.
106 public void clearBuffer() {
110 this.resumeEof
= false;