当前位置: 首页>>代码示例>>Java>>正文


Java ResourceManager.getResource方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:undertow-io,项目名称:undertow.js,代码行数:19,代码来源:Templates.java

示例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;
}
 
开发者ID:automenta,项目名称:spimedb,代码行数:15,代码来源:ChainedResourceManager.java

示例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);
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:40,代码来源:UndertowWeb.java

示例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;
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:16,代码来源:UndertowWeb.java


注:本文中的io.undertow.server.handlers.resource.ResourceManager.getResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。