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

pipiz.util.UrlUtils Maven / Gradle / Ivy

The newest version!
package pipiz.util;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class UrlUtils {

    public static URI convertToUri(String s) {
        if (s == null || s.isEmpty()) {
            return null;
        }

        URI uri = null;
        try {
            uri = URI.create(s);
        } catch (IllegalArgumentException e) {
            try {
                URL url = new URL(s);
                uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
            } catch (MalformedURLException | URISyntaxException e1) {
                e1.printStackTrace();
            }
        }
        return uri;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy