com.google.common.io.Resources.readLines()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中com.google.common.io.Resources.readLines方法的一些代码示例,展示了Resources.readLines的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.readLines方法的具体详情如下:
包路径:com.google.common.io.Resources
类名称:Resources
方法名:readLines

Resources.readLines介绍

[英]Reads all of the lines from a URL. The lines do not include line-termination characters, but do include other leading and trailing whitespace.

This method returns a mutable List. For an ImmutableList, use Resources.asCharSource(url, charset).readLines().
[中]读取URL中的所有行。这些行不包含行终止字符,但包含其他前导和尾随空格。
此方法返回一个可变列表。对于不可变列表,请使用资源。asCharSource(url,字符集)。readLines()。

代码示例

代码示例来源:origin: prestodb/presto

protected PrestoCliLauncher()
    throws IOException
{
  nationTableInteractiveLines = readLines(getResource("com/facebook/presto/tests/cli/interactive_query.results"), UTF_8);
  nationTableBatchLines = readLines(getResource("com/facebook/presto/tests/cli/batch_query.results"), UTF_8);
}

代码示例来源:origin: springside/springside4

/**
 * 读取文件的每一行,读取规则见本类注释.
 */
public static List<String> toLines(String resourceName) throws IOException {
  return Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8);
}

代码示例来源:origin: springside/springside4

/**
 * 读取文件的每一行,读取规则见本类注释.
 */
public static List<String> toLines(Class<?> contextClass, String resourceName) throws IOException {
  return Resources.readLines(Resources.getResource(contextClass, resourceName), Charsets.UTF_8);
}

代码示例来源:origin: google/guava

return readLines(
  url,
  charset,

代码示例来源:origin: google/j2objc

return readLines(
  url,
  charset,

代码示例来源:origin: CalebFenton/simplify

public static List<String> load(String path) {
  URL url = Resources.getResource(path);
  List<String> lines = new LinkedList<>();
  try {
    lines = Resources.readLines(url, Charsets.UTF_8);
  } catch (IOException e) {
    e.printStackTrace();
  }
  removeNonDefinitionLines(lines);
  return lines;
}

代码示例来源:origin: testcontainers/testcontainers-java

public static void assertLicenseAccepted(final String imageName) {
    try {
      final URL url = Resources.getResource(ACCEPTANCE_FILE_NAME);
      final List<String> acceptedLicences = Resources.readLines(url, Charsets.UTF_8);

      if (acceptedLicences.stream().map(String::trim).anyMatch(imageName::equals)) {
        return;
      }
    } catch (Exception ignored) {
      // suppressed
    }

    throw new IllegalStateException("The image " + imageName + " requires you to accept a license agreement. " +
            "Please place a file at the root of the classpath named " + ACCEPTANCE_FILE_NAME + ", e.g. at " +
            "src/test/resources/" + ACCEPTANCE_FILE_NAME + ". This file should contain the line:\n  " +
            imageName);

  }
}

代码示例来源:origin: wildfly/wildfly

return readLines(
  url,
  charset,

代码示例来源:origin: google/guava

public void testReadLines() throws IOException {
 // TODO(chrisn): Check in a better resource
 URL resource = getClass().getResource("testdata/i18n.txt");
 assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
}

代码示例来源:origin: apache/mahout

public WordConverter() {
 try {
  words = Resources.readLines(Resources.getResource("words.txt"), Charsets.UTF_8,
                new LineProcessor<List<String>>() {
    private final List<String> theWords = Lists.newArrayList();
    @Override
    public boolean processLine(String line) {
     Iterables.addAll(theWords, onSpace.split(line));
     return true;
    }
    @Override
    public List<String> getResult() {
     return theWords;
    }
   });
 } catch (IOException e) {
  throw new ImpossibleException(e);
 }
}

代码示例来源:origin: prestodb/presto

public static String loadPolygon(String path)
      throws IOException
  {
    URL resource = requireNonNull(GeometryBenchmarkUtils.class.getClassLoader().getResource(path), "resource not found: " + path);
    List<String> lines = readLines(resource, UTF_8);
    String line = lines.get(0);
    String[] parts = line.split("\\|");
    return parts[0];
  }
}

代码示例来源:origin: google/guava

private void doExtensiveTest(String resourceName) throws IOException {
  Splitter splitter = Splitter.on(CharMatcher.whitespace());
  URL url = getClass().getResource(resourceName);
  for (String line : Resources.readLines(url, UTF_8)) {
   Iterator<String> iterator = splitter.split(line).iterator();
   String input = iterator.next();
   String expectedOutput = iterator.next();
   assertFalse(iterator.hasNext());
   assertEquals(expectedOutput, simplifyPath(input));
  }
 }
}

代码示例来源:origin: google/guava

public void testReadLines_withLineProcessor() throws IOException {
 URL resource = getClass().getResource("testdata/alice_in_wonderland.txt");
 LineProcessor<List<String>> collectAndLowercaseAndTrim =
   new LineProcessor<List<String>>() {
    List<String> collector = new ArrayList<>();
    @Override
    public boolean processLine(String line) {
     collector.add(whitespace().trimFrom(line));
     return true;
    }
    @Override
    public List<String> getResult() {
     return collector;
    }
   };
 List<String> result =
   Resources.readLines(resource, Charsets.US_ASCII, collectAndLowercaseAndTrim);
 assertEquals(3600, result.size());
 assertEquals("ALICE'S ADVENTURES IN WONDERLAND", result.get(0));
 assertEquals("THE END", result.get(result.size() - 1));
}

代码示例来源:origin: languagetool-org/languagetool

private void addIgnoreWords() throws IOException {
 hunspellDict.addWord(SpellingCheckRule.LANGUAGETOOL);
 hunspellDict.addWord(SpellingCheckRule.LANGUAGETOOLER);
 URL ignoreUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(getIgnoreFileName());
 List<String> ignoreLines = Resources.readLines(ignoreUrl, Charsets.UTF_8);
 for (String ignoreLine : ignoreLines) {
  if (!ignoreLine.startsWith("#")) {
   hunspellDict.addWord(ignoreLine);
  }
 }
}

代码示例来源:origin: apache/mahout

Matrix readTsv(String name) throws IOException {
 Splitter onTab = Splitter.on("\t");
 List<String> lines = Resources.readLines((Resources.getResource(name)), Charsets.UTF_8);
 int rows = lines.size();
 int columns = Iterables.size(onTab.split(lines.get(0)));
 Matrix r = new DenseMatrix(rows, columns);
 int row = 0;
 for (String line : lines) {
  Iterable<String> values = onTab.split(line);
  int column = 0;
  for (String value : values) {
   r.set(row, column, Double.parseDouble(value));
   column++;
  }
  row++;
 }
 return r;
}

代码示例来源:origin: apache/metron

@Test
public void testCEFParserCyberArk() throws Exception {
  runTest("cyberark", Resources.readLines(Resources.getResource(getClass(), "cyberark.cef"), UTF_8),
      Resources.toString(Resources.getResource(getClass(), "cyberark.schema"), UTF_8),
      Resources.toString(Resources.getResource(getClass(), "cyberark.json"), UTF_8));
}

代码示例来源:origin: apache/metron

@Test
public void testCEFParserAdallom() throws Exception {
  runTest("adallom", Resources.readLines(Resources.getResource(getClass(), "adallom.cef"), UTF_8),
      Resources.toString(Resources.getResource(getClass(), "adallom.schema"), UTF_8));
}

代码示例来源:origin: apache/metron

@Test
public void testCEFParserWAF() throws Exception {
  URL waf_url = Resources.getResource(getClass(), "waf.cef");
  runTest("waf", Resources.readLines(waf_url, UTF_8),
      Resources.toString(Resources.getResource(getClass(), "waf.schema"), UTF_8));
}

代码示例来源:origin: apache/metron

@Test
public void testPaloAltoCEF() throws Exception {
  URL palo_url = Resources.getResource(getClass(), "palo.cef");
  runTest("palo", Resources.readLines(palo_url, UTF_8),
      Resources.toString(Resources.getResource(getClass(), "palo.schema"), UTF_8));
}

代码示例来源:origin: xuminwlt/j360-dubbo-app-all

/**
 * 读取文件的每一行,读取规则见本类注释.
 */
public static List<String> toLines(Class<?> contextClass, String resourceName) throws IOException {
  return Resources.readLines(Resources.getResource(contextClass, resourceName), Charsets.UTF_8);
}

相关文章