Get a resource from the GATE ClassLoader as an InputStream.
(String resourceName)
| 345 | /** Get a resource from the GATE ClassLoader as an InputStream. |
| 346 | */ |
| 347 | public static InputStream getResourceAsStream(String resourceName) |
| 348 | throws IOException { |
| 349 | // Strip any leading '/' |
| 350 | if(resourceName.charAt(0) == '/') { |
| 351 | resourceName = resourceName.substring(1); |
| 352 | } |
| 353 | |
| 354 | ClassLoader gcl = Gate.getClassLoader(); |
| 355 | if(gcl == null) { |
| 356 | // if the GATE ClassLoader has not been initialised yet (i.e. this |
| 357 | // method was called before Gate.init) then fall back to the current |
| 358 | // classloader |
| 359 | return Files.class.getClassLoader().getResourceAsStream(resourceName); |
| 360 | } |
| 361 | else { |
| 362 | // if we can, get the resource through the GATE ClassLoader to allow |
| 363 | // loading of resources from plugin JARs as well as gate.jar |
| 364 | return gcl.getResourceAsStream(resourceName); |
| 365 | } |
| 366 | //return ClassLoader.getSystemResourceAsStream(resourceName); |
| 367 | } // getResourceAsStream(String) |
| 368 | |
| 369 | /** Get a resource from the GATE resources directory as an InputStream. |
| 370 | * The resource name should be relative to <code>resourcePath</code> which |
no test coverage detected