APISonar


com.google.common.io.Files.toString

> com > google > common > io > Files > toString
com APIs google APIs common APIs io APIs Files APIs toString APIs

Example 1
private String readEntirePacFile() throws IOException {
    String pac = Files.toString(pacFile, Charset.defaultCharset());
    return pac.replaceAll("\\s+", " ").trim();
  }
Example 2
protected String getTranslatedFile(String fileName) throws IOException {
    File f = new File(tempDir, fileName);
    assertTrue(f.exists());
    return Files.toString(f, Charset.defaultCharset());
  }
Example 3
private String getSource(String path) throws IOException {
    File file = findSourceFile(path);
    if (file == null) {
      return findArchivedSource(path);
    } else {
      return Files.toString(file, Charset.defaultCharset());
    }
  }
Example 4
private String getFileContent(String path) {
    try {
      return Files.toString(new File(path), Charset.defaultCharset());
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
Example 5
private static String readFile(File file) {
        try {
            return Files.toString(file, Charsets.UTF_8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Example 6
private static String getFileContent(File filename)
        throws IOException {
        return Files.toString(filename, Charsets.UTF_8);
    }
Example 7
private static String mavenVersion() {
    try {
      String pomXml = Files.toString(new File("pom.xml"), UTF_8);
      return substringBetween(pomXml, "<version>", "</version>");
    } catch (IOException e) {
      throw new RuntimeException("Unable to read maven version", e);
    }
  }
Example 8
private static String fileContents(File input) {
        try {
            return Files.toString(input, Charsets.UTF_8);
        } catch (IOException e) {
            return throwUnchecked(e, String.class);
        }
    }
Example 9
public TemporaryJobBuilder imageFromInfoFile(final File file) {
    final String json;
    try {
      json = Files.toString(file, UTF_8);
    } catch (IOException e) {
      throw new AssertionError("Failed to read image info file: "
                               + file + ": " + e.getMessage());
    }
    return imageFromInfoJson(json, file.toString());
  }
Example 10
public void loadRefasterJsTemplate(String refasterjsTemplate) throws IOException  {
    Preconditions.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.toString(new File(refasterjsTemplate), UTF_8);
  }
Example 11
public void generateSampleOutput() throws IOException {
    File testDataDir = TestDataHelper.getTestDataScenario(this, "compute_abi");
    String source = Files.toString(
        new File(testDataDir, "generateSampleOutput.src"), UTF_8);
    String original = compile("A.java", source);

    String expected = Files.toString(
        new File(testDataDir, "generateSampleOutput.expected"), UTF_8);

    assertEquals(expected, original);
  }
Example 12
public void testEscapeColumnWithDoubleQuote() throws IOException {
    String[] colNames = { "column\"withdoublequote" };
    String[] types = { "VARCHAR(50)"};
    String[] vals = { "'hello, world'"};
    createTableWithColTypesAndNames(colNames, types, vals);
    String[] args = getArgv();
    runImport(args);

    Path filePath = new Path(getTablePath(), "part-m-00000");
    String output = Files.toString(new File(filePath.toString()), Charsets.UTF_8);

    assertEquals("hello, world", output.trim());
  }
Example 13
public static String loadDemoFlowYaml(String classPath) {
        URL resource = TestBase.class.getClassLoader().getResource(classPath);
        try {
            return Files.toString(new File(resource.getFile()), Charset.forName("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
Example 14
private void assertMethodsPresent(String path, String... methods) throws IOException {
        String content = Files.toString(folder.getRoot().toPath().resolve(path).toFile(), UTF_8);
        assertThat(content, stringContainsInOrder(asList(methods)));
    }
Example 15
public void getResourceAsTempFile_contents() throws IOException {
    File file = Resources.getResourceAsTempFile("some_resource.txt");

    assertThat(Files.toString(file, Charsets.UTF_8)).isEqualTo("A resource!");
  }
Example 16
public static String evaluateExternal(String template) throws IOException {
    if (template.startsWith(EXTERNAL_PREFIX)) {
      File file = new File(template.substring(EXTERNAL_PREFIX.length()));
      logger.info("Reading configuration value from file {}", file.getPath());
      try {
        return Files.toString(file, UTF_8).trim();
      } catch (IOException exception) {
        logger.error("Error reading configuration value '{}':{}",
            template, exception);
        throw exception;
      }
    }

    return template;
  }
Example 17
protected String getResourceBodyString(final String resource) throws IOException {
        final String resourcePath = Resources.getResource(resource).getPath();
        final File catalogFile = new File(resourcePath);
        return Files.toString(catalogFile, Charset.forName("UTF-8"));
    }
Example 18
public static String readFileContentToString(String filePath)
            throws IOException {
        String content = "";
        content = Files.toString(new File(filePath), Charsets.UTF_8);
        return content;
    }
Example 19
private void recordManifestUsages(Path manifest)
      throws IOException, ParserConfigurationException, SAXException {
    String xml = Files.toString(manifest.toFile(), UTF_8);
    Document document = XmlUtils.parseDocument(xml, true);
    recordManifestUsages(document.getDocumentElement());
  }
Example 20
protected void replaceInFile(String fileName, String from, String to) throws IOException {
        File wsdlFile = new File(getResourceBase(), fileName);
        String wsdl = Files.toString(wsdlFile, Charset.forName("UTF-8"));

        wsdl = wsdl.replace(from, to);

        Files.write(wsdl, wsdlFile, Charset.forName("UTF-8"));
    }
Example 21
private static long getCurrentTotalIdleTimeInJiffies() {
    try {
      File file = new File("/proc/stat");
      String content = Files.toString(file, US_ASCII);
      String value = Iterables.get(WHITESPACE_SPLITTER.split(content), 5);
      return Long.parseLong(value);
    } catch (NumberFormatException | IOException e) {
      return 0L;
    }
  }
Example 22
public void testAllChecksPresentOnAvailableChecksPage() throws IOException {
        final String availableChecks = Files.toString(AVAILABLE_CHECKS_FILE, UTF_8);
        for (File file : Files.fileTreeTraverser().preOrderTraversal(JAVA_SOURCES_DIRECTORY)) {
            final String fileName = file.getName();
            if (fileName.matches(CHECK_FILE_NAME) && !IGNORE_LIST.contains(fileName)) {
                final String checkName = fileName.replace(CHECK_SUFFIX, "");
                if (!isPresent(availableChecks, checkName)) {
                    Assert.fail(checkName + " is not correctly listed on Available Checks page"
                            + " - add it to " + AVAILABLE_CHECKS_PATH);
                }
            }
        }
    }
Example 23
public void canDownloadFromAUrlDirectly() throws IOException, URISyntaxException {
    URI uri = httpd.getUri("/example");

    Path output = outputDir.resolve("cheese");
    downloader.fetch(BuckEventBusFactory.newInstance(), uri, output);

    assertEquals("cheese", Files.toString(output.toFile(), UTF_16));
  }
Example 24
private void test(String caseName) throws Exception {
    File file = new File("src/test/resources/yaml/" + caseName);

    String yamlContent = Files.toString(file, Charsets.UTF_8);

    check(yamlContent);
  }
Example 25
static void updateLibVersion(String modulePath, String property, String version)
            throws IOException {
        File pomFile = new File(BASE_DIR + "/" + modulePath + "/pom.xml");
        String pom = Files.toString(pomFile, UTF_8);
        pom = pom.replaceAll("<" + property + ">.*",
                "<" + property + ">" + version + "</" + property + ">");
        Files.write(pom, pomFile, UTF_8);
        System.out.println(property + " : " + version);
        report.println(property + " : " + version);
    }