Java URI from toUri(String endpoint, Protocol protocol)

Here you can find the source of toUri(String endpoint, Protocol protocol)

Description

to Uri

License

Open Source License

Parameter

Parameter Description
endpoint the endpoint.
protocol the protocol.

Exception

Parameter Description
IllegalArgumentException if the inputs are null.

Return

an URI for the given endpoint. Prefixes the protocol if the endpoint given does not have it.

Declaration

public static URI toUri(String endpoint, Protocol protocol) 

Method Source Code

//package com.java2s;
/*/*from   w w w . j av a2s .  c  o  m*/
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;

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

public class Main {
    /**
     * @param endpoint the endpoint.
     * @param config the client configuration.
     * @return an URI for the given endpoint. Prefixes the protocol if the
     * endpoint given does not have it.
     *
     * @throws IllegalArgumentException if the inputs are null.
     */
    public static URI toUri(String endpoint, ClientConfiguration config) {

        if (config == null) {
            throw new IllegalArgumentException("ClientConfiguration cannot be null");
        }
        return toUri(endpoint, config.getProtocol());
    }

    /**
     * @param endpoint the endpoint.
     * @param protocol the protocol.
     * @return an URI for the given endpoint. Prefixes the protocol if the
     * endpoint given does not have it.
     *
     * @throws IllegalArgumentException if the inputs are null.
     */
    public static URI toUri(String endpoint, Protocol protocol) {
        if (endpoint == null) {
            throw new IllegalArgumentException("endpoint cannot be null");
        }

        /*
         * If the endpoint doesn't explicitly specify a protocol to use, then
         * we'll defer to the default protocol specified in the client
         * configuration.
         */
        if (!endpoint.contains("://")) {
            endpoint = protocol.toString() + "://" + endpoint;
        }

        try {
            return new URI(endpoint);
        } catch (final URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. toURI(final java.io.File file, final StringBuilder builder)
  2. toURI(final String location)
  3. toURI(final String path)
  4. toURI(final String uriString)
  5. toUri(java.io.File file)
  6. toURI(String filePath)
  7. toUri(String ip, String path)
  8. toURI(String location)
  9. toURI(String location)