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

com.vtence.molecule.testing.http.URLEscaper Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
package com.vtence.molecule.testing.http;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;

public class URLEscaper {

    private final Charset charset;

    public URLEscaper(Charset charset) {
        this.charset = charset;
    }

    public static URLEscaper to(Charset charset) {
        return new URLEscaper(charset);
    }

    public String escape(String text) {
        try {
            return URLEncoder.encode(text, charset.name());
        } catch (UnsupportedEncodingException impossible) {
            // We can safely ignore since we already have a charset
            throw new AssertionError(impossible);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy