本文整理汇总了Java中nl.siegmann.epublib.domain.Resource.close方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.close方法的具体用法?Java Resource.close怎么用?Java Resource.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nl.siegmann.epublib.domain.Resource
的用法示例。
在下文中一共展示了Resource.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeLazyLoadedResources
import nl.siegmann.epublib.domain.Resource; //导入方法依赖的package包/类
private void closeLazyLoadedResources() {
if ( currentBook != null ) {
for ( Resource res: currentBook.getResources().getAll() ) {
res.close();
}
}
}
示例2: loadEmbeddedFont
import nl.siegmann.epublib.domain.Resource; //导入方法依赖的package包/类
public void loadEmbeddedFont( String name, String resourceHRef ) {
LOG.debug("Attempting to load custom font from href " + resourceHRef );
if ( loadedTypeFaces.containsKey(name) ) {
LOG.debug("Already have font " + resourceHRef + ", aborting.");
return;
}
Resource res = textLoader.getCurrentBook().getResources().getByFileName( resourceHRef );
if ( res == null ) {
LOG.error("No resource found for href " + resourceHRef );
return;
}
File tempFile = new File(context.getCacheDir(), UUID.randomUUID().toString() );
try {
IOUtil.copy( res.getInputStream(), new FileOutputStream(tempFile));
res.close();
Typeface typeface = Typeface.createFromFile(tempFile);
FontFamily fontFamily = new FontFamily( name, typeface );
LOG.debug("Loaded embedded font with name " + name );
loadedTypeFaces.put(name, fontFamily);
} catch ( IOException io ) {
LOG.error("Could not load embedded font " + name, io );
} finally {
tempFile.delete();
}
}
示例3: getCSSRules
import nl.siegmann.epublib.domain.Resource; //导入方法依赖的package包/类
public List<CompiledRule> getCSSRules( String href ) {
if ( this.cssRules.containsKey(href) ) {
return Collections.unmodifiableList(cssRules.get(href));
}
List<CompiledRule> result = new ArrayList<>();
if ( currentBook == null ) {
return result;
}
String strippedHref = href.substring( href.lastIndexOf('/') + 1);
Resource res = null;
for ( Resource resource: this.currentBook.getResources().getAll() ) {
if ( resource.getHref().endsWith(strippedHref) ) {
res = resource;
break;
}
}
if ( res == null ) {
LOG.error("Could not find CSS resource " + strippedHref );
return new ArrayList<>();
}
StringWriter writer = new StringWriter();
try {
IOUtil.copy(res.getReader(), writer);
List<Rule> rules = CSSParser.parse(writer.toString());
LOG.debug("Parsed " + rules.size() + " raw rules.");
for ( Rule rule: rules ) {
if ( rule.getSelectors().size() == 1 && rule.getSelectors().get(0).toString().equals("@font-face")) {
handleFontLoadingRule(rule);
} else {
result.add(CSSCompiler.compile(rule, htmlSpanner));
}
}
} catch (IOException io) {
LOG.error("Error while reading resource", io);
return new ArrayList<>();
} catch (Exception e) {
LOG.error("Error reading CSS file", e);
} finally {
res.close();
}
cssRules.put(href, result);
LOG.debug("Compiled " + result.size() + " CSS rules.");
return result;
}