Java URI Parse parse(final String uri)

Here you can find the source of parse(final String uri)

Description

Creates or obtains a new URI;.

License

Apache License

Parameter

Parameter Description
uri the uri

Exception

Parameter Description
URISyntaxException the URI syntax exception

Return

the uri

Declaration

public static URI parse(final String uri) throws URISyntaxException 

Method Source Code

//package com.java2s;
/*//from  www  .  j  a  v a  2  s .  co m
 * Copyright: Almende B.V. (2014), Rotterdam, The Netherlands
 * License: The Apache Software License, Version 2.0
 */

import java.lang.ref.WeakReference;
import java.net.URI;
import java.net.URISyntaxException;

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<String, WeakReference<URI>> uris = new HashMap<String, WeakReference<URI>>(100);

    /**
     * Creates or obtains a new URI;.
     *
     * @param uri
     *            the uri
     * @return the uri
     * @throws URISyntaxException
     *             the URI syntax exception
     */
    public static URI parse(final String uri) throws URISyntaxException {
        final WeakReference<URI> ref = uris.get(uri);
        if (ref != null) {
            final URI res = ref.get();

            if (res != null) {
                return res;
            }
        }
        final URI newUri = new URI(uri.intern());
        uris.put(uri, new WeakReference<URI>(newUri));
        return newUri;
    }
}

Related

  1. parse(final URI uri, boolean decodeQueryParam)
  2. parseAWSUri(URI uri, String defaultAccessKey, String defaultSecretAccessKey)
  3. parseLeaf(final URI uri)
  4. parseParameters(URI uri)