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