String path = Packages.absolutePath(clazz, fileName);
Application app = Application.get();
// first try default class loading locator to find the resource
IResourceStream stream = app.getResourceSettings()
.getResourceStreamLocator()
.locate(clazz, path);
if (stream == null)
{
// if default locator couldnt find the resource, than some fallback
stream = new ResourceStreamLocator().locate(clazz, path);
}
if (stream == null)
{
throw new IllegalArgumentException("resource " + fileName + " not found for scope " +
clazz + " (path = " + path + ")");
}
setLastModified(stream.lastModifiedTime());
try
{
if (encoding != null)
{
buffer.append(Streams.readString(stream.getInputStream(), encoding));
}
else
{
buffer.append(Streams.readString(stream.getInputStream()));
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
catch (ResourceStreamNotFoundException e)
{
throw new RuntimeException(e);
}
finally
{
try
{
stream.close();
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}