APISonar


com.google.common.io.Files.readLines

> com > google > common > io > Files > readLines
com APIs google APIs common APIs io APIs Files APIs readLines APIs

Example 1
private void assertContents(List<Path> destFiles, List<String> contents)
      throws Exception {
    for (int i = 0; i < destFiles.size(); ++i) {
      assertThat(
          Files.readLines(destFiles.get(i).toFile(), StandardCharsets.UTF_8),
          containsInAnyOrder(contents.get(i)));
    }
  }
Example 2
private static List<String> readPropertiesFile(File propFile) throws IOException {
        // properties files must be ISO_8859_1
        return Files.readLines(propFile, ISO_8859_1);
    }
Example 3
public static String getFileAsString(String component, String fileName){
        try {
            return Files.readLines(getFile(component, fileName), StandardCharsets.UTF_8).stream().collect(joining());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Example 4
private JSONArray readFile(String fileName) throws Exception {
    String file1 = SendCoinShieldTest.class.getClassLoader()
        .getResource("json" + File.separator + fileName).getFile();
    List<String> readLines = Files.readLines(new File(file1),
        Charsets.UTF_8);

    JSONArray array = JSONArray
        .parseArray(readLines.stream().reduce((s, s2) -> s + s2).get());

    return array;
  }
Example 5
public void visitFile(File file) {
    List<String> lines;
    try {
      lines = Files.readLines(file, charset);
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
    for (String line : lines) {
      if (line.contains("\t")) {
        addIssueOnFile("Replace all tab characters in this file by sequences of white-spaces.");
        break;
      }
    }
  }
Example 6
private static String fileAsString(File file){
        try {
            return Files.readLines(file, StandardCharsets.UTF_8).stream().collect(joining("\n"));
        } catch (IOException e) {
            die("Could not read file " + file.getPath());
            throw new RuntimeException(e);
        }
    }
Example 7
public static String slurp(String loc) {
    try {
      return Joiner.on("\n").join(Files.readLines( new File(loc), Charset.defaultCharset())).trim();
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
Example 8
public List<String> readCustomArguments() {
		File file = new File(parentDirectory, FILE_NAME);
		if (!file.exists()) {
			return emptyList();
		}

		try {
			List<String> lines = Files.readLines(file, Charsets.UTF_8);
			return parseLines(lines);
		} catch (IOException e) {
			return emptyList();
		}
	}
Example 9
public static Iterable<String> getData(String sensor) throws IOException {
    return Iterables.filter(
            Files.readLines(new File("src/test/resources/example_data/" + sensor), Charset.defaultCharset()),
            s -> !s.startsWith("#") && s.length() > 0
    );
  }
Example 10
private void addMacSpecificPath() {
    File pathFile = new File("/etc/paths");
    if (pathFile.exists()) {
      try {
        pathSegmentBuilder.addAll(Files.readLines(pathFile, Charsets.UTF_8));
      } catch (IOException e) {
        // Guess we won't include those, then
      }
    }
  }
Example 11
protected static List<String> getParameterFromFile(File sqlFile) throws IOException {
        String sqlFileName = sqlFile.getAbsolutePath();
        int prefixIndex = sqlFileName.lastIndexOf(".sql");
        String dataFielName = sqlFileName.substring(0, prefixIndex) + ".dat";
        File dataFile = new File(dataFielName);
        List<String> parameters = Files.readLines(dataFile, Charset.defaultCharset());
        return parameters;
    }
Example 12
private Pair<Integer, Integer> getExpectedRowAndCol(File expectResultFile) throws IOException {
        List<String> lines = Files.readLines(expectResultFile, Charset.forName("UTF-8"));
        int row = -1;
        int col = -1;
        try {
            row = Integer.parseInt(lines.get(0).trim());
        } catch (Exception ex) {
        }
        try {
            col = Integer.parseInt(lines.get(1).trim());
        } catch (Exception ex) {
        }
        return Pair.newPair(row, col);
    }
Example 13
private static ImmutableList<File> getFilesFromFileList(File mainFile, String javaRunfilesRoot)
      throws IOException {
    List<String> metadataFiles = Files.readLines(mainFile, UTF_8);
    ImmutableList.Builder<File> convertedMetadataFiles = new Builder<>();
    for (String metadataFile : metadataFiles) {
      convertedMetadataFiles.add(new File(javaRunfilesRoot + "/" + metadataFile));
    }
    return convertedMetadataFiles.build();
  }
Example 14
public void whenReadMultipleLinesUsingFiles_thenRead() throws IOException {
        final File file = new File("src/test/resources/test2.in");

        final List<String> result = Files.readLines(file, Charsets.UTF_8);
        assertThat(result, contains("John", "Jane", "Adam", "Tom"));
    }
Example 15
public void testBackupPolicies() throws IOException {
    AlertSample.main(new String[]{"backup", "-j", policyFileName});
    File backupFile = new File(policyFileName);
    assertTrue(backupFile.exists());
    String fileContents =
        String.join("\n", Files.readLines(backupFile, StandardCharsets.UTF_8));
    assertTrue(fileContents.contains("test-policy"));
  }
Example 16
private static String[] parseParamFileIfUsed(@Nonnull String[] args) {
    if (args.length != 1 || !args[0].startsWith("@")) {
      return args;
    }
    File paramFile = new File(args[0].substring(1));
    try {
      return Files.readLines(paramFile, StandardCharsets.UTF_8).toArray(new String[0]);
    } catch (IOException e) {
      throw new RuntimeException("Error parsing param file: " + args[0], e);
    }
  }
Example 17
public final void givenUsingGuava_whenIteratingAFile_thenCorrect() throws IOException {
        final String path = "G:\\full\\train\\input\\" + "trainDataNegative.csv";
        // final String path = "G:\\full\\train\\input\\" + "trainDataPositive.csv";

        logMemory();
        Files.readLines(new File(path), Charsets.UTF_8);
        logMemory();
    }
Example 18
public static void loadFromFile(GraknGraph graph, String file) {
        try {
            File graql = new File("src/test/graql/" + file);

            graph.graql()
                    .parseList(Files.readLines(graql, StandardCharsets.UTF_8).stream().collect(joining("\n")))
                    .forEach(Query::execute);
        } catch (IOException |GraknValidationException e){
            throw new RuntimeException(e);
        }
    }
Example 19
private static String readBenchmarkServerUri() {
        try {
            for (String line : Files.readLines(new File("../scripts/benchmarks/servers.txt"),
                    Charset.forName("UTF-8"))) {
                if (line.startsWith("CLIENT")) {
                    String hostname = StringUtils.split(line, '=')[1];
                    return "http://" + hostname + ":" + BENCHMARK_SERVER_PORT;
                }
            }

            throw new SafeIllegalStateException("CLIENT declaration not found in servers.txt");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Example 20
private void testCreate(Path path) throws Exception {
    String expected = "my test string";
    try (Writer writer = Channels.newWriter(
        factory.create(path.toString(), MimeTypes.TEXT), StandardCharsets.UTF_8.name())) {
      writer.write(expected);
    }
    assertThat(
        Files.readLines(path.toFile(), StandardCharsets.UTF_8),
        containsInAnyOrder(expected));
  }
Example 21
public void stores_violations_of_single_rule_in_configured_folder() throws IOException {
        store.save(defaultRule(), ImmutableList.of("first violation", "second violation"));

        Properties properties = readProperties(new File(configuredFolder, "stored.rules"));
        String ruleViolationsFile = properties.getProperty(defaultRule().getDescription());
        assertThat(ruleViolationsFile).isNotBlank();

        List<String> violationLines = Files.readLines(new File(configuredFolder, ruleViolationsFile), UTF_8);
        assertThat(violationLines).containsOnly("first violation", "second violation");
    }
Example 22
public void testWriteLinesToFile() throws IOException {
    File outputFile = tmp.newFile("output.txt");
    ImmutableList<String> lines = ImmutableList.of(
        "The",
        "quick brown fox",
        "jumps over",
        "the lazy dog.");
    MoreFiles.writeLinesToFile(lines, outputFile);

    List<String> observedLines = Files.readLines(outputFile, Charsets.UTF_8);
    assertEquals(lines, observedLines);
  }
Example 23
protected static Set<Component> readTOC(Descriptor descriptor) throws IOException
    {
        File tocFile = new File(descriptor.filenameFor(Component.TOC));
        List<String> componentNames = Files.readLines(tocFile, Charset.defaultCharset());
        Set<Component> components = Sets.newHashSetWithExpectedSize(componentNames.size());
        for (String componentName : componentNames)
        {
            Component component = new Component(Component.Type.fromRepresentation(componentName), componentName);
            if (!new File(descriptor.filenameFor(component)).exists())
                logger.error("Missing component: {}", descriptor.filenameFor(component));
            else
                components.add(component);
        }
        return components;
    }
Example 24
public void visitFile(AstNode astNode) {
    List<String> lines;
    try {
      lines = Files.readLines(getContext().getFile(), charset);
    } catch (IOException e) {
      throw new SonarException(e);
    }
    for (int i = 0; i < lines.size(); i++) {
      String line = lines.get(i);
      if (line.length() > maximumLineLength) {
        getContext().createLineViolation(this, "Split this {0} characters long line (which is greater than {1} authorized).", i + 1, line.length(), maximumLineLength);
      }
    }
  }
Example 25
private String getExecutionLogs() throws Exception {
    GfshExecution gfshExecution = GfshScript.of("start locator").execute(gfshRule);
    File[] files = gfshExecution.getWorkingDir().listFiles();
    String logName = files[0].getAbsolutePath() + "/" + files[0].getName() + ".log";
    return Files.readLines(new File(logName), StandardCharsets.UTF_8).toString();
  }