List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:fi.helsinki.opintoni.sampledata.SampleDataFiles.java
public static String toText(String path) { try {// w ww . j a v a 2s . c om return Files.toString(new File(PREFIX + path), Charset.forName("UTF-8")); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.google.dart.tools.core.html.DartHtmlScriptHelper.java
/** * Parse the given html file and return the content and location of the "application/dart" * scripts./*from w ww . j a v a2 s . co m*/ * * @param file * @return * @throws IOException */ public static List<Token> getDartScripts(File file) throws IOException { return getDartScripts(Files.toString(file, Charsets.UTF_8)); }
From source file:org.sonar.plugins.csharp.sarif.SarifParserFactory.java
public static SarifParser create(File file) { String contents;/* w w w . j ava2 s .co m*/ try { contents = Files.toString(file, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException( "Unable to read the Roslyn SARIF report file: " + file.getAbsolutePath(), e); } JsonParser parser = new JsonParser(); JsonObject root = parser.parse(contents).getAsJsonObject(); if (root.has("version")) { String version = root.get("version").getAsString(); switch (version) { case "0.4": case "0.1": return new SarifParser01And04(contents); case "1.0": default: return new SarifParser10(contents); } } throw new IllegalStateException(String.format( "Unable to parse the Roslyn SARIF report file: %s. Unrecognized format", file.getAbsolutePath())); }
From source file:pt.up.fe.specs.library.IoUtils.java
/** * Helper method for Guava Files.toString, which uses the default Charset * and throws an unchecked exception.//from w ww . ja v a2 s . c om * * @param file * @return */ public static String read(File file) { try { return Files.toString(file, Charset.defaultCharset()); } catch (IOException e) { throw new RuntimeException("Could not read file '" + file + "'", e); } }
From source file:org.sonar.css.FileUtils.java
public static String fileContent(File file, Charset charset) { String fileContent;/*from w w w .j a v a 2s.c om*/ try { fileContent = Files.toString(file, charset); } catch (IOException e) { throw new IllegalStateException("Could not read " + file, e); } return fileContent; }
From source file:com.facebook.buck.test.XmlTestResultParser.java
public static TestCaseSummary parse(File xmlFile) throws IOException { String xmlFileContents = Files.toString(xmlFile, Charsets.UTF_8); try {/*from ww w.j av a2 s . c om*/ return doParse(xmlFileContents); } catch (NumberFormatException e) { // This is an attempt to track down an inexplicable error that we have observed in the wild. String message = createDetailedExceptionMessage(xmlFile, xmlFileContents); throw new RuntimeException(message, e); } }
From source file:br.com.objectos.jabuticava.debs.CaracteristicasFalso.java
private static String gunzipAndToString(String resourceName) { try {/* www . java 2s . c o m*/ File file = gunzip(CaracteristicasFalso.class, resourceName); return Files.toString(file, Caracteristica.CHARSET); } catch (IOException e) { return ""; } }
From source file:org.glowroot.common.util.PropertiesFiles.java
public static void upgradeIfNeeded(File propFile, Map<String, String> findReplacePairs) throws IOException { // properties files must be ISO_8859_1 String content = Files.toString(propFile, ISO_8859_1); boolean modified = false; for (Map.Entry<String, String> entry : findReplacePairs.entrySet()) { String find = entry.getKey(); if (content.contains(find)) { content = content.replace(find, entry.getValue()); modified = true;/*w ww . j a va 2 s. c om*/ } } if (modified) { Files.write(content, propFile, ISO_8859_1); } }
From source file:com.carmatech.maven.model.MergerTestUtils.java
public static String readProperties(final File targetFile) throws IOException { return Files.toString(targetFile, UTF_8); }
From source file:fi.helsinki.moodi.test.fixtures.Fixtures.java
public static String asString(final String prefix, final String path, final Map<String, ?> variables) { try {/*w w w . ja v a 2 s. c o m*/ final String content = Files.toString(new File(prefix + path), Charset.forName("UTF-8")); return Templates.render(content, variables); } catch (IOException e) { throw new RuntimeException(e); } }