View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.util.database;
5   
6   import java.io.InputStream;
7   
8   /**
9    * Helper class for retrieving resources relative to the installation.
10   * @author Stuart Turton
11   */
12  public class ResourceLoader {
13  
14    public InputStream getResourceStream(String path) throws java.io.IOException {
15      ClassLoader cl = this.getClass().getClassLoader();
16      if (cl == null) {
17        cl = ClassLoader.getSystemClassLoader();
18      }
19      InputStream stream = cl.getResourceAsStream(path);
20      if (stream == null) {
21        throw new java.io.IOException("Resource not found: " + path);
22      }
23      return stream;
24    }
25    
26  }