X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FNextableInputStreamStep.java;fp=src%2Fbe%2Fnikiroo%2Futils%2FNextableInputStreamStep.java;h=ab2256266bbfbdd0d76a8359ed0c3de22aed8ed2;hb=4098af704dfa22ce4a60003940753c28030374fa;hp=0000000000000000000000000000000000000000;hpb=2e7584daaf5d2f06d326c21297a71d02dd275a35;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/NextableInputStreamStep.java b/src/be/nikiroo/utils/NextableInputStreamStep.java new file mode 100755 index 0000000..ab22562 --- /dev/null +++ b/src/be/nikiroo/utils/NextableInputStreamStep.java @@ -0,0 +1,52 @@ +package be.nikiroo.utils; + +public class NextableInputStreamStep { + private int stopAt; + private boolean disabled; + private int pos; + private int resumeLen; + private int last = -1; + private int skip; + + public NextableInputStreamStep(int byt) { + stopAt = byt; + } + + // do NOT stop twice on the same item + public int stop(byte[] buffer, int pos, int len) { + for (int i = pos; i < len; i++) { + if (buffer[i] == stopAt) { + if (i > this.last) { + // we skip the sep + this.skip = 1; + + this.pos = pos; + this.resumeLen = len; + this.last = i; + return i; + } + } + } + + return -1; + } + + public int getResumeLen() { + return resumeLen; + } + + public int getSkip() { + return skip; + } + + public void clearBuffer() { + this.last = -1; + this.pos = 0; + this.skip = 0; + this.resumeLen = 0; + } + + public boolean isEnabled() { + return !disabled; + } +}