org.javawebstack.httpserver.util.ResourceFileProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-server Show documentation
Show all versions of http-server Show documentation
This library provides a routing and request mapping stack on top of the well known and industry proven eclipse jetty http server. It also supports websockets.
package org.javawebstack.httpserver.util;
import java.io.InputStream;
public class ResourceFileProvider implements FileProvider {
private final ClassLoader classLoader;
private final String prefix;
public ResourceFileProvider(ClassLoader classLoader, String prefix) {
this.classLoader = classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
this.prefix = prefix;
}
public ResourceFileProvider(String prefix) {
this(null, prefix);
}
public InputStream getFile(String path) {
return classLoader.getResourceAsStream(prefix + ((!prefix.endsWith("/") && !path.startsWith("/")) ? "/" : "") + path);
}
}