@Override
    public synchronized void write(int b) throws IOException {
        if (MBYTES[match] == b) { // another byte matched. Good. Keep going...
            match++;
            if (match == MBYTES.length) {
                // don't send MARK to the output, but instead notify the callback
                onMarkFound();
                match = 0;
            }
        } else {
            if (match > 0) {
                // only matched partially. send the partial match that we held off down the pipe
                base.write(MBYTES, 0, match);
                match = 0;

                // this might match the first byte in MARK, so retry.
                write(b);
            } else {
                base.write(b);
            }
        }
    }
@Test
    public void findTwice() throws IOException {
        write("foo" + mark + "bar" + mark);
        assertCount(2);
        assertOutput("foobar");
    }