001package com.nimbusds.oauth2.sdk.util;
002
003
004import java.net.URI;
005import java.net.URISyntaxException;
006
007
008/**
009 * URI operations.
010 */
011public class URIUtils {
012
013
014        /**
015         * Gets the base part (schema, host, port and path) of the specified
016         * URI.
017         *
018         * @param uri The URI. May be {@code null}.
019         *
020         * @return The base part of the URI, {@code null} if the original URI
021         *         is {@code null} or doesn't specify a protocol.
022         */
023        public static URI getBaseURI(final URI uri) {
024
025                if (uri == null)
026                        return null;
027
028                try {
029                        return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null);
030
031                } catch (URISyntaxException e) {
032
033                        return null;
034                }
035        }
036
037
038        /**
039         * Prevents instantiation.
040         */
041        private URIUtils() {
042
043                // do nothing
044        }
045}