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


Java ResourceURL类代码示例

本文整理汇总了Java中io.dropwizard.servlets.assets.ResourceURL的典型用法代码示例。如果您正苦于以下问题:Java ResourceURL类的具体用法?Java ResourceURL怎么用?Java ResourceURL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceURL类属于io.dropwizard.servlets.assets包,在下文中一共展示了ResourceURL类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderLocalAsset

import io.dropwizard.servlets.assets.ResourceURL; //导入依赖的package包/类
private CachedPage renderLocalAsset(URL localSourceUrl) throws IOException {
    return new CachedPage(Resources.toByteArray(localSourceUrl),
            ResourceURL.getLastModified(localSourceUrl),
            com.google.common.net.MediaType.CSS_UTF_8.toString());
}
 
开发者ID:rnorth,项目名称:dropwizard-markdown-assets-bundle,代码行数:6,代码来源:MarkdownAssetsServlet.java

示例2: load

import io.dropwizard.servlets.assets.ResourceURL; //导入依赖的package包/类
@Override
public Asset load(String key) throws Exception {
  for (Map.Entry<String, String> mapping : resourcePathToUriMappings.entrySet()) {
    if (!key.startsWith(mapping.getValue())) {
      continue;
    }

    Asset asset = loadOverride(key);
    if (asset != null) {
      return asset;
    }

    final String requestedResourcePath =
            SLASHES.trimFrom(key.substring(mapping.getValue().length()));
    final String absolutePath = SLASHES.trimFrom(mapping.getKey() + requestedResourcePath);

    try {
      URL requestedResourceUrl =
          UrlUtil.switchFromZipToJarProtocolIfNeeded(Resources.getResource(absolutePath));
      if (ResourceURL.isDirectory(requestedResourceUrl)) {
        if (indexFilename != null) {
          requestedResourceUrl = Resources.getResource(absolutePath + '/' + indexFilename);
          requestedResourceUrl =
              UrlUtil.switchFromZipToJarProtocolIfNeeded(requestedResourceUrl);
        } else {
          // resource mapped to directory but no index file defined
          continue;
        }
      }

      long lastModified = ResourceURL.getLastModified(requestedResourceUrl);
      if (lastModified < 1) {
        // Something went wrong trying to get the last modified time: just use the current time
        lastModified = System.currentTimeMillis();
      }

      // zero out the millis; the If-Modified-Since header will not have them
      lastModified = (lastModified / 1000) * 1000;
      return new StaticAsset(Resources.toByteArray(requestedResourceUrl), lastModified);
    } catch (IllegalArgumentException expected) {
      // Try another Mapping.
    }
  }

  return null;
}
 
开发者ID:dropwizard-bundles,项目名称:dropwizard-configurable-assets-bundle,代码行数:47,代码来源:AssetServlet.java


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