Java Class Loader getStreamForPath(ClassLoader loader, String path)

Here you can find the source of getStreamForPath(ClassLoader loader, String path)

Description

get Stream For Path

License

Apache License

Declaration

static InputStream getStreamForPath(ClassLoader loader, String path)
            throws IOException 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.io.*;

import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    static InputStream getStreamForPath(ClassLoader loader, String path)
            throws IOException {
        URL url = loader.getResource(path);

        if (url == null) {
            return null;
        }/*from w  w w.  j  a v a 2s.c om*/

        // This *should* handle Tomcat better, where the Tomcat class loader appears to be caching
        // the contents of files; this bypasses Tomcat to re-read the files from the disk directly.

        if (url.getProtocol().equals("file")) {
            try {
                return new FileInputStream(new File(url.toURI()));
            } catch (URISyntaxException e) {
                return null;
            }
        }

        return url.openStream();
    }
}

Related

  1. getManifest(ClassLoader cl, String extension)
  2. getPackageFolder(String packageName, ClassLoader classLoader)
  3. getParentClassLoader()
  4. getProjectClassLoader(IJavaProject javaProject)
  5. getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader)
  6. getToolsClassLoader()
  7. isBizServicesLocatorXmlLoaded(File f, ClassLoader classLoader)
  8. load(Class serviceClass, ClassLoader loader)
  9. load(String className)