public class ClassResourceLoader extends BufferedResourceLoader
For example, suppose the classpath contains:
com/foo/SomeThing.class com/foo/my-template.cs com/foo/subdir/another-template.cs
You can access the resources in the class's package like this:
ResourceLoader loader = new ClassResourceLoader(SomeThing.class); loader.open("my-template.cs"); loader.open("subdir/my-template.cs");Or by using a relative path:
ResourceLoader loader = new ClassResourceLoader(Something.class, "subdir"); loader.open("my-template.cs");
ResourceLoader
,
ClassLoaderResourceLoader
DEFAULT_BUFFER_SIZE, DEFAULT_CHARACTER_SET
Constructor and Description |
---|
ClassResourceLoader(Class<?> cls) |
ClassResourceLoader(Class<?> cls,
String basePath)
Load resources from the given subdirectory
basePath ,
relative to the .class file of cls . |
Modifier and Type | Method and Description |
---|---|
Reader |
open(String name)
Open a resource.
|
Reader |
openOrFail(String name)
Open a resource or throw an exception if no such resource is found.
|
buffer, getBufferSize, getCharacterSet, setBufferSize, setCharacterSet
close, getKey, getResourceVersionId
public ClassResourceLoader(Class<?> cls)
public Reader open(String name) throws IOException
ResourceLoader
ResourceLoader.close(Reader)
when done with the
reader.name
- the name of the resourceIOException
- if resource fails to openpublic Reader openOrFail(String name) throws JSilverTemplateNotFoundException, IOException
ResourceLoader
ResourceLoader.close(Reader)
when done with the
reader.name
- the name of the resourceJSilverTemplateNotFoundException
- if resource is not foundIOException
- if resource fails to openCopyright © 2010–2017 Google. All rights reserved.