APISonar


com.google.common.io.Files.asCharSource

> com > google > common > io > Files > asCharSource
com APIs google APIs common APIs io APIs Files APIs asCharSource APIs

Example 1
public static Set<String> loadWhitelistedJsWarnings(File file) {
    return loadWhitelistedJsWarnings(
        Files.asCharSource(file, UTF_8));
  }
Example 2
private static Map<String, String> loadGoldenSchemas(File goldensDir) {
    return Stream.of(goldensDir.listFiles())
        .collect(Collectors.toMap(
            File::getName,
            goldenFile -> {
              try {
                return Files.asCharSource(goldenFile, UTF_8).read();
              } catch (IOException e) {
                throw new UncheckedIOException(e);
              }
            }
        ));
  }
Example 3
protected String getTranslatedFile(String fileName) throws IOException {
    File f = new File(tempDir, fileName);
    assertTrue(fileName + " not generated", f.exists());
    return Files.asCharSource(f, options.fileUtil().getCharset()).read();
  }
Example 4
private static String readJavaCode(String fileName) {
    try {
      return Files.asCharSource(new File(fileName), Charset.forName("UTF-8")).read();
    } catch (IOException ex) {
      throw new RuntimeException("impossible to read the file " + fileName, ex);
    }
  }
Example 5
public void appendTo(
      Appendable out,
      DependencyInfo info,
      File content, Charset contentCharset) throws IOException {
    appendTo(out, info, Files.asCharSource(content, contentCharset));
  }
Example 6
public static final String readFileFromClasspathAsString(String fileName) throws IOException
  {
    return Files.asCharSource(
        new File(SketchAggregationTest.class.getClassLoader().getResource(fileName).getFile()),
        Charset.forName("UTF-8")
    ).read();
  }
Example 7
private Stacktrace loadStackTrace(String testName) throws IOException {
    return Stacktrace.parse(
        Files.asCharSource(getStackTraceFile(testName), StandardCharsets.UTF_8).read());
  }
Example 8
private String formatError(String baseMessageFormat, Object... args) {
    String baseMessage = String.format(baseMessageFormat, args);
    if (printWorkerLog) {
      try {
        worker.outputLogger().flush();
        String logContent = Files.asCharSource(outputFile, UTF_8).read();
        return baseMessage + " Worker log follows:\n\n" + logContent;
      } catch (IOException ignore) {
        // fall through to printing the path
      }
    }

    return baseMessage + String.format(" Inspect %s to see any worker output.", outputFile);
  }
Example 9
public void loadRefasterJsTemplate(String refasterjsTemplate) throws IOException  {
    checkState(
        templateJs == null, "Can't load RefasterJs template since a template is already loaded.");
    this.templateJs =
        Thread.currentThread().getContextClassLoader().getResource(refasterjsTemplate) != null
            ? Resources.toString(Resources.getResource(refasterjsTemplate), UTF_8)
            : Files.asCharSource(new File(refasterjsTemplate), UTF_8).read();
  }
Example 10
public WebhookModule(Options options) {
    this.webhookConfig = Optional.ofNullable(options.webhookConfigFile)
        .map(f -> {
          try {
            return Files.asCharSource(options.webhookConfigFile, StandardCharsets.UTF_8).read();
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
        });
  }
Example 11
private static Iterable<String> getArgsFromFlagFile(String flagFileName) throws IOException {
    String flagFileContent =
        Files.asCharSource(new File(flagFileName), StandardCharsets.UTF_8).read();
    return Splitter.on('\n').omitEmptyStrings().split(flagFileContent);
  }
Example 12
private static long getCurrentTotalIdleTimeInJiffies() {
    try {
      File file = new File("/proc/stat");
      String content = Files.asCharSource(file, US_ASCII).read();
      String value = Iterables.get(WHITESPACE_SPLITTER.split(content), 5);
      return Long.parseLong(value);
    } catch (NumberFormatException | IOException e) {
      return 0L;
    }
  }
Example 13
public TrustSource add(File trustedCAPemFile) {
        if (trustedCAPemFile == null) {
            throw new IllegalArgumentException("Trusted CA file cannot be null");
        }

        String pemFileContents;
        try {
            pemFileContents = Files.asCharSource(trustedCAPemFile, StandardCharsets.UTF_8).read();
        } catch (IOException e) {
            throw new UncheckedIOException("Unable to read file containing PEM-encoded trusted CAs: " + trustedCAPemFile.getAbsolutePath(), e);
        }

        return add(pemFileContents);
    }
Example 14
private static DeadCodeMap loadDeadCodeMap() {
    File file = Options.getProGuardUsageFile();
    if (file != null) {
      try {
        return ProGuardUsageParser.parse(Files.asCharSource(file, Charset.defaultCharset()));
      } catch (IOException e) {
        throw new AssertionError(e);
      }
    }
    return null;
  }
Example 15
public void testTypeInference() throws IOException {
    StringWriter stringWriter = new StringWriter();
    try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
      ByteCodeTypePrinter.printClassesWithTypes(JAR_PATH, printWriter);
      printWriter.close();
    }
    String inferenceResult = stringWriter.toString().trim();
    String golden = Files.asCharSource(GOLDEN_PATH.toFile(), StandardCharsets.UTF_8).read().trim();
    assertThat(inferenceResult).isEqualTo(golden);
  }
Example 16
public static String resolveConfIndirection(String valInConf)
      throws IOException {
    if (valInConf == null) return null;
    if (!valInConf.startsWith("@")) {
      return valInConf;
    }
    String path = valInConf.substring(1).trim();
    return Files.asCharSource(new File(path), Charsets.UTF_8).read().trim();
  }
Example 17
public static JClient from(String file) throws IOException
    {
        return GSON.fromJson(Files.asCharSource(new File(file), StandardCharsets.UTF_8).read(), JClient.class);
    }
Example 18
public void testSchemaGeneration() throws Exception {
    runCommand(
        "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql",
        "--db_host=" + containerHostName,
        "--db_port=" + containerPort);

    // We don't verify the exact contents of the result SQL file because that would be too brittle,
    // but we check to make sure that a couple parts of it are named as we expect them to be
    // TODO: try running the schema against the test database.
    File sqlFile = new File(tmp.getRoot(), "schema.sql");
    assertThat(sqlFile.exists()).isTrue();
    String fileContent = Files.asCharSource(sqlFile, UTF_8).read();
    assertThat(fileContent).contains("create table \"Domain\" (");
    assertThat(fileContent).contains("repo_id text not null,");
  }
Example 19
static String readTierFile(Options options) {
    try {
      File tierConfig = options.tierConfigFile;
      return tierConfig == null
          ? Resources.toString(
              TierModule.class.getClassLoader().getResource(TIER_CONFIG_PATH),
              StandardCharsets.UTF_8)
          : Files.asCharSource(tierConfig, StandardCharsets.UTF_8).read();
    } catch (IOException e) {
      LOG.error("Error loading tier configuration file.");
      throw new RuntimeException(e);
    }
  }
Example 20
public void whenReadMultipleCharSources_thenRead() throws IOException {
        final String expectedValue = "Hello worldTest";
        final File file1 = new File("src/test/resources/test1.in");
        final File file2 = new File("src/test/resources/test1_1.in");

        final CharSource source1 = Files.asCharSource(file1, Charsets.UTF_8);
        final CharSource source2 = Files.asCharSource(file2, Charsets.UTF_8);
        final CharSource source = CharSource.concat(source1, source2);

        final String result = source.read();

        assertEquals(expectedValue, result);
    }
Example 21
private InputFile generateTestFile(String sourceFile) throws IOException {
    File source = new File(sourceFile);
    File target = new File(temp.newFolder(), source.getName()).getAbsoluteFile();
    String content = Files.asCharSource(source, StandardCharsets.UTF_8)
      .read()
      .replaceAll("\\r\\n", "\n")
      .replaceAll("\\r", "\n")
      .replaceAll("\\n", eol);
    Files.asCharSink(target, StandardCharsets.UTF_8).write(content);
    return TestUtils.inputFile(target);
  }
Example 22
public static RootLexicon loadInto(RootLexicon lexicon, File input) throws IOException {
    return Files
        .asCharSource(input, Charsets.UTF_8).readLines(new TextLexiconProcessor(lexicon));
  }
Example 23
public InfinitestConfiguration getConfiguration() {
		if (!file.exists()) {
			return InfinitestConfiguration.empty();
		}
		CharSource charSource = Files.asCharSource(file, Charsets.UTF_8);
		try {
			return new InfinitestConfigurationParser().parseFileContent(charSource);
		} catch (IOException e) {
			throw new RuntimeException("Error loading configuration", e);
		}
	}
Example 24
public static SimpleBackoffNgramModel fromArpa(File arpaModel, float unigramWeigth)
      throws IOException {
    if (unigramWeigth < 0 || unigramWeigth > 1) {
      throw new IllegalArgumentException(
          "Unigram weight must be between 0 and 1 but it is:" + unigramWeigth);
    }
    ArpaLoader converter = new ArpaLoader(unigramWeigth);
    return Files.asCharSource(arpaModel, Charsets.UTF_8).readLines(converter);
  }
Example 25
public void testBazelUserManual() throws Exception {
    String documentationFilePath = "site/docs/user-manual.html";
    if (OS.getCurrent() == OS.WINDOWS) {
      documentationFilePath = WindowsTestUtil.getRunfile("io_bazel/" + documentationFilePath);
    }
    final File documentationFile = new File(documentationFilePath);
    DocumentationTestUtil.validateUserManual(
        Bazel.BAZEL_MODULES,
        BazelRuleClassProvider.create(),
        Files.asCharSource(documentationFile, UTF_8).read());
  }