本文整理匯總了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);
}