本文整理汇总了Java中io.undertow.server.handlers.resource.ResourceManager.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceManager.getResource方法的具体用法?Java ResourceManager.getResource怎么用?Java ResourceManager.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.handlers.resource.ResourceManager
的用法示例。
在下文中一共展示了ResourceManager.getResource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadTemplate
import io.undertow.server.handlers.resource.ResourceManager; //导入方法依赖的package包/类
public static String loadTemplate(String template, ResourceManager resourceManager) throws Exception {
byte[] buf = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
Resource resource = resourceManager.getResource(template);
if(resource == null) {
throw UndertowScriptLogger.ROOT_LOGGER.templateNotFound(template);
}
try (InputStream stream = resource.getUrl().openStream()) {
if(stream == null) {
throw UndertowScriptLogger.ROOT_LOGGER.templateNotFound(template);
}
int res;
while ((res = stream.read(buf)) > 0) {
out.write(buf, 0, res);
}
return out.toString("UTF-8");
}
}
示例2: getResource
import io.undertow.server.handlers.resource.ResourceManager; //导入方法依赖的package包/类
@Override
public Resource getResource(String p) {
for (int i = 0, managersSize = size(); i < managersSize; i++) {
ResourceManager x = get(i);
try {
Resource y = x.getResource(p);
if (y != null)
return y;
} catch (Throwable ignored) {
//ignore
}
}
return null;
}
示例3: wrapWithStaticHandler
import io.undertow.server.handlers.resource.ResourceManager; //导入方法依赖的package包/类
protected HttpHandler wrapWithStaticHandler(HttpHandler baseHandler, String path) {
// static path is given relative to application root
if (!new File(path).isAbsolute()) {
path = WunderBoss.options().get("root", "").toString() + File.separator + path;
}
if (!new File(path).exists()) {
log.debug("Not adding static handler for nonexistent directory {}", path);
return baseHandler;
}
log.debug("Adding static handler for {}", path);
final ResourceManager resourceManager =
new CachingResourceManager(1000, 1L, null,
new FileResourceManager(new File(path), 1 * 1024 * 1024), 250);
String[] welcomeFiles = new String[] { "index.html", "index.html", "default.html", "default.htm" };
final List<String> welcomeFileList = new CopyOnWriteArrayList<>(welcomeFiles);
final ResourceHandler resourceHandler = new ResourceHandler()
.setResourceManager(resourceManager)
.setWelcomeFiles(welcomeFiles)
.setDirectoryListingEnabled(false);
return new PredicateHandler(new Predicate() {
@Override
public boolean resolve(HttpServerExchange value) {
try {
Resource resource = resourceManager.getResource(value.getRelativePath());
if (resource == null) {
return false;
}
if (resource.isDirectory()) {
Resource indexResource = getIndexFiles(resourceManager, resource.getPath(), welcomeFileList);
return indexResource != null;
}
return true;
} catch (IOException ex) {
return false;
}
}
}, resourceHandler, baseHandler);
}
示例4: getIndexFiles
import io.undertow.server.handlers.resource.ResourceManager; //导入方法依赖的package包/类
protected Resource getIndexFiles(ResourceManager resourceManager, final String base, List<String> possible) throws IOException {
String realBase;
if (base.endsWith("/")) {
realBase = base;
} else {
realBase = base + "/";
}
for (String possibility : possible) {
Resource index = resourceManager.getResource(realBase + possibility);
if (index != null) {
return index;
}
}
return null;
}