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

org.mockserver.model.StringBody Maven / Gradle / Ivy

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

/**
 * @author jamesdbloom
 */
public class StringBody extends Body {

    private final String value;
    private final byte[] rawBinaryData;

    public StringBody(String value, byte[] rawBinaryData) {
        super(Type.STRING);
        this.value = value;
        this.rawBinaryData = rawBinaryData;
    }

    public StringBody(String value, Type type) {
        super(type);
        this.value = value;
        if (value != null) {
            this.rawBinaryData = value.getBytes();
        } else {
            this.rawBinaryData = new byte[0];
        }
    }

    public static StringBody exact(String body) {
        return new StringBody(body, Type.STRING);
    }

    public static StringBody regex(String body) {
        return new StringBody(body, Type.REGEX);
    }

    public static StringBody xpath(String body) {
        return new StringBody(body, Type.XPATH);
    }

    public static StringBody json(String body) {
        return new StringBody(body, Type.JSON);
    }

    public String getValue() {
        return value;
    }

    public byte[] getRawBytes() {
        return rawBinaryData;
    }

    @Override
    public String toString() {
        return value;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy