当前位置: 首页>>代码示例>>Java>>正文


Java CharSource.readLines方法代码示例

本文整理汇总了Java中com.google.common.io.CharSource.readLines方法的典型用法代码示例。如果您正苦于以下问题:Java CharSource.readLines方法的具体用法?Java CharSource.readLines怎么用?Java CharSource.readLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.CharSource的用法示例。


在下文中一共展示了CharSource.readLines方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processLines

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public void processLines( final Object stream, final Consumer<String> callback )
    throws Exception
{
    final CharSource source = toCharSource( stream );
    source.readLines( new LineProcessor<Object>()
    {
        @Override
        public boolean processLine( final String line )
            throws IOException
        {
            callback.accept( line );
            return true;
        }

        @Override
        public Object getResult()
        {
            return null;
        }
    } );
}
 
开发者ID:purplejs,项目名称:purplejs,代码行数:22,代码来源:CoreLibHelper.java

示例2: fromCharSource

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public static List<Rewrite> fromCharSource(CharSource source) throws IOException {
  return source.readLines(new LineProcessor<List<Rewrite>>() {
    private List<Rewrite> refactorings = new ArrayList<>();
    private final Splitter SPLITTER = Splitter.on("->").trimResults().omitEmptyStrings();

    @Override
    public List<Rewrite> getResult() {
      return Collections.unmodifiableList(refactorings);
    }

    @Override
    public boolean processLine(String line) {
      List<String> parts = SPLITTER.splitToList(line);
      refactorings.add(Rewrite.of(parts.get(0), parts.get(1), Rewrite.Visit.Expressions));
      return true;
    }
  });
}
 
开发者ID:Sable,项目名称:mclab-core,代码行数:19,代码来源:Rewrites.java

示例3: loadEDLMentionsFrom

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public ImmutableList<EDLMention> loadEDLMentionsFrom(CharSource source) throws IOException {
  final ImmutableList.Builder<EDLMention> ret = ImmutableList.builder();

  int lineNo = 0;
  for (final String line : source.readLines()) {
    ++lineNo;
    try {
      ret.add(parseMention(line));
    } catch (IOException ioe) {
      throw new IOException("Illegal EDL line #" + lineNo + ":\n" + line + "\n"
          + ioe.getMessage());
    }
  }

  return ret.build();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:17,代码来源:EDLLoader.java

示例4: stringSetFrom

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public static Set<String> stringSetFrom(final CharSource supplier) throws IOException {
  final LineProcessor<Set<String>> callback = new LineProcessor<Set<String>>() {
    private final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    @Override
    public boolean processLine(final String s) {
      builder.add(s.trim());
      return true;
    }

    @Override
    public Set<String> getResult() {
      return builder.build();
    }
  };

  supplier.readLines(callback);
  return callback.getResult();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:20,代码来源:StringUtils.java

示例5: loadStringMultimap

import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
 * Loads a file in the format {@code key value1 value2 value3} (tab-separated) into a {@link
 * com.google.common.collect.Multimap} of {@code String} to {@code String}. Each key should only
 * appear on one line, and there should be no duplicate values. Each key and value has whitespace
 * trimmed off. Skips empty lines and allows comment-lines with {@code #} in the first position.
 * If a key has no values, it will not show up in the keySet of the returned multimap.
 */
public static ImmutableMultimap<String, String> loadStringMultimap(CharSource multimapSource)
    throws IOException {
  final ImmutableMultimap.Builder<String, String> ret = ImmutableMultimap.builder();

  int count = 0;
  for (final String line : multimapSource.readLines()) {
    ++count;
    if (isCommentLine(line)) {
      continue;
    }
    final List<String> parts = multimapSplitter.splitToList(line);
    if (parts.isEmpty()) {
      continue;
    }
    ret.putAll(parts.get(0), skip(parts, 1));
  }

  return ret.build();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:27,代码来源:FileUtils.java

示例6: loadSymbolTable

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public static ImmutableTable<Symbol, Symbol, Symbol> loadSymbolTable(CharSource input)
    throws IOException {
  final ImmutableTable.Builder<Symbol, Symbol, Symbol> ret = ImmutableTable.builder();

  int lineNo = 0;
  for (final String line : input.readLines()) {
    final List<String> parts = StringUtils.onTabs().splitToList(line);
    if (parts.size() != 3) {
      throw new IOException(String.format("Invalid line %d when reading symbol table: %s",
          lineNo, line));
    }
    ret.put(Symbol.from(parts.get(0)), Symbol.from(parts.get(1)), Symbol.from(parts.get(2)));
    ++lineNo;
  }

  return ret.build();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:18,代码来源:FileUtils.java

示例7: importSymbolsFrom

import com.google.common.io.CharSource; //导入方法依赖的package包/类
private static Optional<MutableSymbolTable> importSymbolsFrom(CharSource cs) {
  try {
    ImmutableList<String> lines = cs.readLines();
    MutableSymbolTable newTable = new MutableSymbolTable();
    for (String line : lines) {

      String[] tokens = line.split("\\s+");
      String sym = tokens[0];
      Integer index = Integer.parseInt(tokens[1]);
      newTable.put(sym, index);
    }
    return Optional.of(newTable);
  } catch (IOException e1) {
    throw Throwables.propagate(e1);
  }
}
 
开发者ID:steveash,项目名称:jopenfst,代码行数:17,代码来源:Convert.java

示例8: read

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public List<InputRecord> read(CharSource source) throws IOException {
  return source.readLines(new LineProcessor<List<InputRecord>>() {
    private final List<InputRecord> recs = Lists.newArrayList();

    @Override
    public boolean processLine(String line) throws IOException {
      if (isBlank(line)) {
        return true;
      }
      if (isComment(line)) {
        return true;
      }

      InputRecord maybe = reader.parse(line);
      if (maybe != null) {
        recs.add(maybe);
      }
      return true;
    }

    @Override
    public List<InputRecord> getResult() {
      return recs;
    }
  });
}
 
开发者ID:steveash,项目名称:jg2p,代码行数:27,代码来源:InputReader.java

示例9: visit

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public void visit(Consumer consumer, final InputStream stream) throws IOException {
    CharSource source = new CharSource() {
        @Override
        public Reader openStream() throws IOException {
            return new BufferedReader(new InputStreamReader(stream));
        }
    };
    ImmutableList<String> lines = source.readLines();
    for (ListIterator<String> iterator = lines.listIterator(); iterator.hasNext(); ) {
        String line = iterator.next();
        LineHandler handler = this.getLineHandler(line);
        if (handler != null) {
            handler.handle(line, consumer, iterator);
        }
    }
}
 
开发者ID:xhibit,项目名称:Teletask-api,代码行数:17,代码来源:PrintedFileVisitor.java

示例10: testLoadSaveEquals

import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Test
public void testLoadSaveEquals() throws IOException, InvalidConfigurationException {
    C config = newTestConfig();
    File tempFile = File.createTempFile("config", ".yml");
    URL modifiedURL = Resources.getResource(getClass(), getModifiedResource());
    URL defaultURL = Resources.getResource(getClass(), getDefaultResource());
    CharSource originalIn = Resources.asByteSource(modifiedURL).asCharSource(Charsets.UTF_8);
    CharSink out = Files.asCharSink(tempFile, Charsets.UTF_8);
    CharSource fileIn = Files.asCharSource(tempFile, Charsets.UTF_8);
    originalIn.copyTo(out);
    load(config, tempFile, defaultURL);
    save(config, tempFile, defaultURL);
    List<String> originalLines = originalIn.readLines();
    originalLines = Lists.transform(originalLines, (s) -> s.replaceAll("\\s", "")); // Strip whitespace
    List<String> fileLines = fileIn.readLines();
    fileLines = Lists.transform(fileLines, (s) -> s.replaceAll("\\s", "")); // Strip whitespace
    assertEquals(originalLines, fileLines);
}
 
开发者ID:TechzoneMC,项目名称:TechUtils,代码行数:19,代码来源:AnnotationConfigTest.java

示例11: loadFrom

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public final CorpusQueryAssessments loadFrom(final CharSource source) throws IOException {
  final List<String> lines = source.readLines();
  final List<QueryResponse2016> queries = Lists.newArrayList();
  final Map<QueryResponse2016, String> metadata = Maps.newHashMap();
  final ImmutableMultimap.Builder<QueryResponse2016, Symbol> responsesToSystems =
      ImmutableMultimap.builder();
  final Map<QueryResponse2016, QueryAssessment2016> assessments = Maps.newHashMap();
  Optional<String> lastMetadata = Optional.absent();
  for (final String line : lines) {
    if (line.startsWith("#")) {
      lastMetadata = Optional.of(line.trim().substring(1));
    } else {
      final String[] parts = line.trim().split("\t");
      checkArgument(parts.length == 5, "expected five columns, but got " + parts.length);
      final Symbol queryID = Symbol.from(parts[0]);
      final Symbol docID = Symbol.from(parts[1]);
      final String[] systemIDs = parts[2].split(",");
      final ImmutableSortedSet<CharOffsetSpan> spans = extractPJSpans(parts[3]);
      final QueryAssessment2016 assessment = QueryAssessment2016.valueOf(parts[4]);
      final QueryResponse2016 query =
          QueryResponse2016.builder().queryID(queryID).docID(docID)
              .addAllPredicateJustifications(spans).build();
      queries.add(query);
      for(final String systemID: systemIDs) {
        responsesToSystems.put(query, Symbol.from(systemID));
      }
      if (!assessment.equals(QueryAssessment2016.UNASSESSED)) {
        assessments.put(query, assessment);
      }
      if (lastMetadata.isPresent()) {
        metadata.put(query, lastMetadata.get());
        lastMetadata = Optional.absent();
      }
    }
  }
  return CorpusQueryAssessments.builder().addAllQueryReponses(queries).assessments(assessments)
      .queryResponsesToSystemIDs(responsesToSystems.build())
      .metadata(metadata).build();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:40,代码来源:SingleFileQueryAssessmentsLoader.java

示例12: setupLoadOnly

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public void setupLoadOnly(String deobfFileName, boolean loadAll)
{
    try
    {
        File mapData = new File(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
        CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
        List<String> srgList = srgSource.readLines();
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList)
        {
            String[] parts = Iterables.toArray(splitter.split(line),String.class);
            String typ = parts[0];
            if ("CL".equals(typ))
            {
                parseClass(builder, parts);
            }
            else if ("MD".equals(typ) && loadAll)
            {
                parseMethod(parts);
            }
            else if ("FD".equals(typ) && loadAll)
            {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    }
    catch (IOException ioe)
    {
        FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());

}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:40,代码来源:FMLDeobfuscatingRemapper.java

示例13: setupLoadOnly

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public void setupLoadOnly(String deobfFileName, boolean loadAll)
{
    try
    {
        File mapData = new File(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
        CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
        List<String> srgList = srgSource.readLines();
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.<String,String>builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList)
        {
            String[] parts = Iterables.toArray(splitter.split(line),String.class);
            String typ = parts[0];
            if ("CL".equals(typ))
            {
                parseClass(builder, parts);
            }
            else if ("MD".equals(typ) && loadAll)
            {
                parseMethod(parts);
            }
            else if ("FD".equals(typ) && loadAll)
            {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    }
    catch (IOException ioe)
    {
        FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());

}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:40,代码来源:FMLDeobfuscatingRemapper.java

示例14: setup

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName)
{
    this.classLoader = classLoader;
    try
    {
        InputStream classData = getClass().getResourceAsStream(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(classData);
        CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
        List<String> srgList = srgSource.readLines();
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.<String,String>builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList)
        {
            String[] parts = Iterables.toArray(splitter.split(line),String.class);
            String typ = parts[0];
            if ("CL".equals(typ))
            {
                parseClass(builder, parts);
            }
            else if ("MD".equals(typ))
            {
                parseMethod(parts);
            }
            else if ("FD".equals(typ))
            {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    }
    catch (IOException ioe)
    {
        FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data");
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:40,代码来源:FMLDeobfuscatingRemapper.java

示例15: verify

import com.google.common.io.CharSource; //导入方法依赖的package包/类
public static void verify() {
    CharSource at = Resources.asCharSource(Resources.getResource("META-INF/factorization_at.cfg"), Charsets.UTF_8);
    if (at == null) {
        throw new IllegalArgumentException("AT is missing!");
    }
    try {
        Splitter bannana = Splitter.on(" ").trimResults();
        for (String line : at.readLines()) {
            int rem = line.indexOf("#");
            if (rem != -1) {
                line = line.substring(0,  rem);
            }
            currentLine = line = line.trim();
            if (line.equals("")) continue;
            List<String> parts = bannana.splitToList(line);
            if (parts.size() == 0) continue;
            String access, className, member;
            if (parts.size() == 3) {
                access = parts.get(0);
                className = parts.get(1);
                member = parts.get(2);
            } else if (parts.size() == 2) {
                access = parts.get(0);
                className = parts.get(1);
                member = null;
                if (className.contains("$")) continue; // Yeah. :/
            } else {
                throw new IllegalArgumentException("Malformed AT? " + line);
            }
            try {
                validate(access, className, member);
            } catch (Throwable t) {
                throw new IllegalArgumentException(t);
            }
        }
    } catch (IOException e) {
        throw new IllegalArgumentException("Handling: " + currentLine, e);
    }
}
 
开发者ID:purpleposeidon,项目名称:Factorization,代码行数:40,代码来源:AtVerifier.java


注:本文中的com.google.common.io.CharSource.readLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。