class StreamDemarcator extends AbstractDemarcator {

    public byte[] nextToken() throws IOException {
        byte[] token = null;
        int j = 0;
        nextTokenLoop:
        while (token == null && this.availableBytesLength != -1) {
            if (this.index >= this.availableBytesLength) {
                this.fill();
            }
            if (this.availableBytesLength != -1) {
                byte byteVal;
                int i;
                for (i = this.index; i < this.availableBytesLength; i++) {
                    byteVal = this.buffer[i];

                    boolean delimiterFound = false;
                    if (this.delimiterBytes != null && this.delimiterBytes[j] == byteVal) {
                        if (++j == this.delimiterBytes.length) {
                            delimiterFound = true;
                        }
                    } else {
                        j = 0;
                    }

                    if (delimiterFound) {
                        this.index = i + 1;
                        int size = this.index - this.mark - this.delimiterBytes.length;
                        token = this.extractDataToken(size);
                        this.mark = this.index;
                        j = 0;
                        if (token != null) {
                            break nextTokenLoop;
                        }
                    }
                }
                this.index = i;
            } else {
                token = this.extractDataToken(this.index - this.mark);
            }
        }

        return token;
    }

    public  StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize);
    public  StreamDemarcator(InputStream is, byte[] delimiterBytes, int maxDataSize, int initialBufferSize);

}