本文整理汇总了Java中com.google.common.io.Resources.asCharSource方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.asCharSource方法的具体用法?Java Resources.asCharSource怎么用?Java Resources.asCharSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.Resources
的用法示例。
在下文中一共展示了Resources.asCharSource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import com.google.common.io.Resources; //导入方法依赖的package包/类
@Override
public String call() throws Exception
{
try
{
final URL resource = Resources.getResource("configurable.txt");
final File f = new File(resource.toURI());
if( !f.exists() )
{
return NO_CONTENT;
}
if( lastMod == 0 || lastMod < f.lastModified() )
{
final CharSource charSource = Resources.asCharSource(resource, Charset.forName("utf-8"));
final StringWriter sw = new StringWriter();
charSource.copyTo(sw);
lastContent = sw.toString();
lastMod = f.lastModified();
}
return lastContent;
}
catch( Exception e )
{
return NO_CONTENT;
}
}
示例2: loadResourceSpecification
import com.google.common.io.Resources; //导入方法依赖的package包/类
ResourceSpecification loadResourceSpecification() {
try {
URL url = Resources.getResource(getClass(), "CloudFormationResourceSpecification.json");
CharSource cs = Resources.asCharSource(url, StandardCharsets.UTF_8);
getLogger().info("Loading CFN resource specification from {}", cs);
ResourceSpecification spec = loadJson(cs);
getLogger().info("CFN resource specification loaded, version = {}", spec.getResourceSpecificationVersion());
return spec;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例3: resourceAsCharsource
import com.google.common.io.Resources; //导入方法依赖的package包/类
private static CharSource resourceAsCharsource(final String resource) throws IOException {
return Resources
.asCharSource(EREToKBPEventOntologyMapper.class.getResource(resource), Charsets.UTF_8);
}
示例4: getResource
import com.google.common.io.Resources; //导入方法依赖的package包/类
private static CharSource getResource(String path) {
URL resource = Resources.getResource(DictionaryUtil.class, path);
return Resources.asCharSource(resource, Charsets.UTF_8);
}
示例5: asCharSource
import com.google.common.io.Resources; //导入方法依赖的package包/类
/**
* Returns a {@link CharSource} view of the resource from which its bytes can be read as
* characters decoded with the given {@code charset}.
*
* @throws NoSuchElementException if the resource cannot be loaded through the class loader,
* despite physically existing in the class path.
* @since 20.0
*/
public final CharSource asCharSource(Charset charset) {
return Resources.asCharSource(url(), charset);
}