Java URL Create buildURL(String spec)

Here you can find the source of buildURL(String spec)

Description

build URL

License

Open Source License

Declaration

public static URL buildURL(String spec) throws MalformedURLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2008 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
 * //www.j a va 2  s  . com
 * Contributors: IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.File;

import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static URL buildURL(String spec) throws MalformedURLException {
        if (spec == null)
            throw new NullPointerException("URL spec is null."); //$NON-NLS-1$
        // Construct the URL carefully so as to preserve UNC paths etc.
        if (spec.startsWith("file:")) { //$NON-NLS-1$
            // need to do this for UNC paths
            File file = new File(spec.substring(5));
            if (file.isAbsolute())
                return file.toURL();
        }
        return new URL(spec);
    }
}

Related

  1. buildUrl(String host, int port, String path, Map parameters)
  2. buildUrl(String host, int port, String path, Map parameters)
  3. buildURL(String host, String path, Map params)
  4. buildURL(String id)
  5. buildUrl(String repositoryUrl, String resourceUrl)
  6. buildURL(String spec)
  7. buildURL(String spec, boolean trailingSlash)
  8. buildURL(String url)
  9. buildUrl(String url)