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

org.everit.json.schema.loader.Uri Maven / Gradle / Ivy

Go to download

Implementation of the JSON Schema Core Draft v4 specification built with the org.json API

There is a newer version: 1.14.4
Show newest version
package org.everit.json.schema.loader;

import static java.util.Objects.requireNonNull;

import java.net.URI;
import java.net.URISyntaxException;

class Uri {

    static Uri parse(String str) throws URISyntaxException {
        URI rawUri = new URI(str);
        int poundIdx = str.indexOf('#');
        String fragment;
        URI toBeQueried;
        if (poundIdx == -1) {
            toBeQueried = rawUri;
            fragment = "";
        } else {
            fragment = str.substring(poundIdx);
            toBeQueried = new URI(str.substring(0, poundIdx));
        }
        return new Uri(toBeQueried, fragment);
    }

    URI toBeQueried;

    String fragment;

    private Uri(URI toBeQueried, String fragment) {
        this.toBeQueried = requireNonNull(toBeQueried, "toBeQueried cannot be null");
        this.fragment = requireNonNull(fragment, "fragment cannot be null");
    }

    URI asJavaURI() {
        try {
            return new URI(toBeQueried + fragment);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy