org.snapscript.common.store.ClassPathStore Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.common.store;
import java.io.InputStream;
import java.io.OutputStream;
public class ClassPathStore implements Store {
private final ClassPathLoader loader;
public ClassPathStore() {
this.loader = new ClassPathLoader(Store.class);
}
@Override
public InputStream getInputStream(String path) {
InputStream source = loader.loadResource(path);
if(source == null) {
int index = path.indexOf('/');
int length = path.length();
if(index == 0 && length > 0) {
String relative = path.substring(1);
int remainder = relative.length();
if(remainder > 0) {
return getInputStream(relative);
}
}
throw new NotFoundException("Could not find '" + path + "'");
}
return source;
}
@Override
public OutputStream getOutputStream(String path) {
return null;
}
}