本文整理汇总了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());
}
示例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;
}