本文整理汇总了Java中com.google.common.io.CharSource.openStream方法的典型用法代码示例。如果您正苦于以下问题:Java CharSource.openStream方法的具体用法?Java CharSource.openStream怎么用?Java CharSource.openStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CharSource
的用法示例。
在下文中一共展示了CharSource.openStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideCssRenamingMap
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/** Reads the CSS rename map */
@Provides
@Singleton
public SoyCssRenamingMap provideCssRenamingMap()
throws IOException {
ImmutableMap.Builder<String, String> cssMapBuilder = ImmutableMap.builder();
URL crUrl = getClass().getResource(CSS_RENAMING_MAP_RESOURCE_PATH);
if (crUrl != null) {
CharSource cssRenamingMapJson = Resources.asCharSource(
crUrl, Charsets.UTF_8);
JsonElement json;
try (Reader jsonIn = cssRenamingMapJson.openStream()) {
json = new JsonParser().parse(jsonIn);
}
for (Map.Entry<String, JsonElement> e
: json.getAsJsonObject().entrySet()) {
cssMapBuilder.put(e.getKey(), e.getValue().getAsString());
}
}
return new SoyCssRenamingMapImpl(cssMapBuilder.build());
}
示例2: parseTree
import com.google.common.io.CharSource; //导入方法依赖的package包/类
static Tree parseTree(CharSource input)
throws IOException
{
try (Reader reader = input.openStream()) {
ThriftLexer lexer = new ThriftLexer(new ANTLRReaderStream(reader));
ThriftParser parser = new ThriftParser(new CommonTokenStream(lexer));
try {
Tree tree = (Tree) parser.document().getTree();
if (parser.getNumberOfSyntaxErrors() > 0) {
throw new IllegalArgumentException("syntax error");
}
return tree;
}
catch (RecognitionException e) {
throw new IllegalArgumentException(e);
}
}
}
示例3: CharSourceLineReader
import com.google.common.io.CharSource; //导入方法依赖的package包/类
public CharSourceLineReader(CharSource charSource) {
try {
reader = charSource.openStream();
} catch (Exception e) {
throw new RuntimeException(e);
}
lineReader = new LineReader(reader);
}
示例4: load
import com.google.common.io.CharSource; //导入方法依赖的package包/类
private static Configuration load(int nextIndex, List<URL> configs)
throws ConfigurationException, IOException {
CharSource input = CharSource.concat(Iterables.transform(configs, URL_TO_SOURCE));
try(Reader reader = input.openStream()) {
return CharStreams.readLines(reader, new ConfigurationParser(nextIndex));
}
}
示例5: givenValidInput_whenGetNextToken_thenProducesFirstToken
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenValidInput_whenGetNextToken_thenProducesFirstToken() throws IOException {
CharSource source = wrap("user-agent: example-bot\n");
RobotsParserImpl parser =new RobotsParserImpl(source.openStream());
Token token = parser.getNextToken();
assertThat(token.image, equalTo("user-agent"));
}
示例6: givenValidInput_whenGetFirstToken_thenProducesFirstToken
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenValidInput_whenGetFirstToken_thenProducesFirstToken() throws IOException {
CharSource source = wrap("user-agent: example-bot\n");
RobotsParserImpl parser =new RobotsParserImpl(source.openStream());
Token token = parser.getToken(1);
assertThat(token.image, equalTo("user-agent"));
}
示例7: givenLargeToken_whenParse_thenResultEqualsExpected
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenLargeToken_whenParse_thenResultEqualsExpected() throws IOException, ParseException {
String useragent = repeat("a", 100000);
CharSource source = wrap("User-agent: " + useragent + "\n");
RobotsParserImpl robotsParser = new RobotsParserImpl(source.openStream());
robotsParser.parse(handler);
handler.userAgent(useragent);
}
示例8: givenDirectiveStartingWithTab_whenParse_producesOtherDirectiveMatchingInput
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenDirectiveStartingWithTab_whenParse_producesOtherDirectiveMatchingInput() throws IOException, ParseException {
CharSource source = wrap("\tfoo: bar");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).otherDirective("\tfoo", "bar");
}
示例9: givenDirectiveStartingWithLineFeed_whenParse_producesOtherDirectiveMatchingInput
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenDirectiveStartingWithLineFeed_whenParse_producesOtherDirectiveMatchingInput() throws IOException, ParseException {
CharSource source = wrap("\ffoo: bar");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).otherDirective("\ffoo", "bar");
}
示例10: givenLowerCaseSiteMapDirective_whenParse_producesSiteMap
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenLowerCaseSiteMapDirective_whenParse_producesSiteMap() throws IOException, ParseException {
CharSource source = wrap("sitemap: sitemap.xml");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).siteMap("sitemap.xml");
}
示例11: givenUpdateCaseSiteMapDirective_whenParse_producesSiteMap
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenUpdateCaseSiteMapDirective_whenParse_producesSiteMap() throws IOException, ParseException {
CharSource source = wrap("SITEMAP: sitemap.xml");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).siteMap("sitemap.xml");
}
示例12: givenUpperCaseAllowDirective_whenParse_producesAllow
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenUpperCaseAllowDirective_whenParse_producesAllow() throws IOException, ParseException {
CharSource source = wrap("user-agent: example-bot\nALLOW: *");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).allow("*");
}
示例13: givenLowerCaseAllowDirective_whenParse_producesAllow
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenLowerCaseAllowDirective_whenParse_producesAllow() throws IOException, ParseException {
CharSource source = wrap("user-agent: example-bot\nallow: *");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).allow("*");
}
示例14: givenUpperCaseDisallowDirective_whenParse_producesDisallow
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenUpperCaseDisallowDirective_whenParse_producesDisallow() throws IOException, ParseException {
CharSource source = wrap("user-agent: example-bot\ndisallow: *");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).disallow("*");
}
示例15: givenLowerCaseDisallowDirective_whenParse_producesDisallow
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void givenLowerCaseDisallowDirective_whenParse_producesDisallow() throws IOException, ParseException {
CharSource source = wrap("user-agent: example-bot\nDISALLOW: *");
RobotsParserImpl parser = new RobotsParserImpl(source.openStream());
parser.parse(handler);
verify(handler).disallow("*");
}