class ZipMatcherBase implements FileAnalyzerFactory.Matcher {

    private static final byte[] MAGIC = {'P', 'K', 3, 4};
    private static final int LOCHDRSIZ = 30;
    private static final int XFHSIZ = 4;

    @Override
    public boolean isPreciseMagic() {
        return true;
    }

    @Override
    public AnalyzerFactory isMagic(byte[] contents, InputStream in)
            throws IOException {<FILL_FUNCTION_BODY>}

    /**
     * Derived classes must implement to get a value indicating if the ZIP
     * "Extra field ID" should be checked to match the value returne by
     * {@link #strictExtraFieldID()}.
     * @return {@code true} if "Extra field ID" should be checked
     */
    protected abstract boolean doesCheckExtraFieldID();

    /**
     * Derived classes that override {@link #doesCheckExtraFieldID()} to return
     * {@code true} must override this method to return the value that must
     * equal an "Extra field ID" in the ZIP file in order for
     * {@link #isMagic(byte[], java.io.InputStream)} to match and return a
     * defined instance.
     * @return {@code null}
     */
    protected Integer strictExtraFieldID() {
        return null;
    }

    private int CH(byte[] b, int n) {
        return b[n] & 0xff;
    }

    private int SH(byte[] b, int n) {
        return CH(b, n) | (CH(b, n + 1) << 8);
    }

    private int LOCNAM(byte[] b) {
        return SH(b, 26);
    }

    private int LOCEXT(byte[] b) {
        return SH(b, 28);
    }
}

        assert in.markSupported();
        if (contents.length < MAGIC.length) {
            return null;
        }
        for (int i = 0; i < MAGIC.length; i++) {
            if (contents[i] != MAGIC[i]) {
                return null;
            }
        }

        if (!doesCheckExtraFieldID()) {
            return forFactory();
        } else {
            byte[] buf = new byte[1024];
            in.mark(buf.length);
            int len = in.read(buf);
            in.reset();

            int xoff = LOCHDRSIZ + LOCNAM(buf);
            int xoffEnd = Math.min(len, xoff + LOCEXT(buf));
            while ((xoff < xoffEnd) && (len - xoff >= XFHSIZ)) {
                int xfhid = SH(buf, xoff);
                if (xfhid == strictExtraFieldID()) {
                    return forFactory();
                }
                int xfdatasiz = SH(buf, xoff + 2);
                xoff += XFHSIZ + xfdatasiz;
            }
            return null;
        }
    
<no_super_class>