Commit | Line | Data |
---|---|---|
4098af70 N |
1 | package be.nikiroo.utils; |
2 | ||
3 | public class NextableInputStreamStep { | |
4 | private int stopAt; | |
5 | private boolean disabled; | |
6 | private int pos; | |
7 | private int resumeLen; | |
8 | private int last = -1; | |
9 | private int skip; | |
10 | ||
11 | public NextableInputStreamStep(int byt) { | |
12 | stopAt = byt; | |
13 | } | |
14 | ||
15 | // do NOT stop twice on the same item | |
16 | public int stop(byte[] buffer, int pos, int len) { | |
17 | for (int i = pos; i < len; i++) { | |
18 | if (buffer[i] == stopAt) { | |
19 | if (i > this.last) { | |
20 | // we skip the sep | |
21 | this.skip = 1; | |
22 | ||
23 | this.pos = pos; | |
24 | this.resumeLen = len; | |
25 | this.last = i; | |
26 | return i; | |
27 | } | |
28 | } | |
29 | } | |
30 | ||
31 | return -1; | |
32 | } | |
33 | ||
34 | public int getResumeLen() { | |
35 | return resumeLen; | |
36 | } | |
37 | ||
38 | public int getSkip() { | |
39 | return skip; | |
40 | } | |
41 | ||
42 | public void clearBuffer() { | |
43 | this.last = -1; | |
44 | this.pos = 0; | |
45 | this.skip = 0; | |
46 | this.resumeLen = 0; | |
47 | } | |
48 | ||
49 | public boolean isEnabled() { | |
50 | return !disabled; | |
51 | } | |
52 | } |