All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockserver.matchers.BinaryMatcher Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.matchers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

/**
 * @author jamesdbloom
 */
public class BinaryMatcher extends BodyMatcher implements Matcher {
    private static Logger logger = LoggerFactory.getLogger(BinaryMatcher.class);
    private final byte[] matcher;

    public BinaryMatcher(byte[] matcher) {
        this.matcher = matcher;
    }

    public boolean matches(byte[] matched) {
        boolean result = false;

        if (matcher == null || matcher.length == 0 || Arrays.equals(matcher, matched)) {
            result = true;
        }

        if (!result) {
            logger.trace("Failed to perform binary match [{}] with [{}] because {}", matched);
        }

        return result;
    }

    @Override
    public String[] fieldsExcludedFromEqualsAndHashCode() {
        return new String[]{"logger"};
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy