Java URI Create getURIWithAuthority(URI uri, String authority)

Here you can find the source of getURIWithAuthority(URI uri, String authority)

Description

Converts URI to a URI with the given authority.

License

Open Source License

Parameter

Parameter Description
uri a parameter
authority a parameter

Declaration

public static URI getURIWithAuthority(URI uri, String authority) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*w  w w .  j a  v a2  s  .  c om*/
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

public class Main {
    /**
     * Converts URI to a URI with the given authority.
     * 
     * @param uri
     * @param authority
     * @return
     */
    public static URI getURIWithAuthority(URI uri, String authority) {
        // TODO Local FS seems to fail when the authority is set
        try {
            if (uri.getScheme() == null)
                return new URI("file", uri.getPath(), null); //$NON-NLS-1$
            if ("gitfs".equals(uri.getScheme())) //$NON-NLS-1$
                return new URI(uri.getScheme(), authority, uri.getPath(), uri.getQuery(), uri.getFragment());
            return uri;
        } catch (URISyntaxException e) {
            // TODO:
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getURIParameterValue(URI uri, String name, String defVal)
  2. getURIs(final Object[] objs)
  3. getUriScheme(String address)
  4. getURIsPrettyPrint(final Collection uris)
  5. getURIStream(Object obj)
  6. stringToUri(String fileString)
  7. stringToURI(String[] str)
  8. uri(String host, String prefix, String path)
  9. uri(String path)