Java URL Connection parseURL(ClassLoader classLoader, String uri)

Here you can find the source of parseURL(ClassLoader classLoader, String uri)

Description

parse URL

License

Open Source License

Declaration

public static InputStream parseURL(ClassLoader classLoader, String uri)
            throws java.io.IOException, java.net.MalformedURLException 

Method Source Code


//package com.java2s;
/*// w w  w .  j a  v  a  2  s .  c o  m
The MIT License (MIT)
    
Copyright (c) 2015 NuBean LLC
    
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import java.io.*;

import java.net.*;

public class Main {
    public static InputStream parseURL(ClassLoader classLoader, String uri)
            throws java.io.IOException, java.net.MalformedURLException {
        URL url = null;
        InputStream input = null;
        if (uri.startsWith("http://") || uri.startsWith("file:///")) {
            url = new URL(uri);
            URLConnection connection = url.openConnection();
            input = connection.getInputStream();
        } else {
            url = classLoader.getResource(uri);
            URLConnection connection = url.openConnection();
            input = connection.getInputStream();
        }

        return input;
    }
}

Related

  1. loadCookie(URL url)
  2. loadJar(String path, URL resource)
  3. loadLinesUrl(String url)
  4. loadObjectFromURL(URL url)
  5. map2URL(final Properties properties)
  6. pingUrl(URL url)
  7. queryComputeAPI(String url)
  8. renderRequest(URLConnection connection)
  9. resolveModuleEntriesFromJar(URL url, String _prefix)