當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。