當前位置: 首頁>>代碼示例>>Java>>正文


Java CharSource.openStream方法代碼示例

本文整理匯總了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());
}
 
開發者ID:mikesamuel,項目名稱:closure-maven-plugin,代碼行數:23,代碼來源:ClosureModule.java

示例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);
        }
    }
}
 
開發者ID:l3ug1m,項目名稱:thrift-java-compiler,代碼行數:19,代碼來源:ThriftIdlParser.java

示例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);
}
 
開發者ID:mayabot,項目名稱:mynlp,代碼行數:9,代碼來源:CharSourceLineReader.java

示例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));
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:8,代碼來源:Configuration.java

示例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"));
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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"));
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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);
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:9,代碼來源:RobotsParserImplTest.java

示例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");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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("*");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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("*");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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("*");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java

示例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("*");
}
 
開發者ID:BrandwatchLtd,項目名稱:robots,代碼行數:8,代碼來源:RobotsParserImplTest.java


注:本文中的com.google.common.io.CharSource.openStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。