List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:com.facebook.buck.jvm.java.autodeps.SymbolExtractor.java
public static Symbols extractSymbols(JavaFileParser javaFileParser, boolean shouldRecordRequiredSymbols, ImmutableSortedSet<Path> absolutePaths) { Set<String> providedSymbols = new HashSet<>(); Set<String> requiredSymbols = new HashSet<>(); Set<String> exportedSymbols = new HashSet<>(); for (Path src : absolutePaths) { String code;//from w w w .j a v a 2 s. c o m try { code = Files.toString(src.toFile(), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } JavaFileParser.JavaFileFeatures features = javaFileParser.extractFeaturesFromJavaCode(code); if (shouldRecordRequiredSymbols) { requiredSymbols.addAll(features.requiredSymbols); exportedSymbols.addAll(features.exportedSymbols); } providedSymbols.addAll(features.providedSymbols); } return new Symbols(providedSymbols, FluentIterable.from(requiredSymbols).filter(SymbolExtractor::isNotABuiltInSymbol), FluentIterable.from(exportedSymbols).filter(SymbolExtractor::isNotABuiltInSymbol)); }
From source file:com.pinterest.rocksplicator.controller.util.ZookeeperConfigParser.java
public static String parseEndpoints(String zkHostsFile, String zkCluster) { Yaml yaml = new Yaml(); try {/*from w w w. j a v a 2 s.c o m*/ String cluster = "default"; if (!Strings.isNullOrEmpty(zkCluster)) { cluster = zkCluster; } String content = Files.toString(new File(zkHostsFile), Charsets.US_ASCII); Map<String, Map<String, List<String>>> config = (Map) yaml.load(content); List<String> endpoints = config.get("clusters").get(cluster); return String.join(",", endpoints); } catch (Exception e) { LOG.error("Cannot parse Zookeeper endpoints!", e); return null; } }
From source file:org.opendaylight.alto.ext.cli.fileconverter.FileConverterHelper.java
public String load(String path) throws Exception { File file = new File(path); return Files.toString(file, StandardCharsets.US_ASCII); }
From source file:omakase.semantics.ProjectReader.java
private static SourceFile readFile(String filename) { String source;//from ww w. j ava2s . c o m try { source = Files.toString(new File(filename), Charset.defaultCharset()); } catch (IOException e) { System.err.format("Error '%s' attempting to open file '%s'.\n", e.toString(), filename); return null; } return new SourceFile(filename, source); }
From source file:org.search.system.tools.FileReader.java
/** * Reads from path//from ww w . j a va2 s . co m * * @param path path to file * @return content of file in UTF-8 * @throws IOException if fileNotFound or bad encoding */ public static String read(String path) throws IOException { return Files.toString(new File(path), Charsets.UTF_8); }
From source file:org.sonar.plugins.cxx.highlighter.SourceFileOffsets.java
private static String fileContent(File file, Charset charset) { String fileContent;/*ww w . j a v a 2s. co m*/ try { fileContent = Files.toString(file, charset); } catch (IOException e) { throw new IllegalStateException("Could not read " + file, e); } return fileContent; }
From source file:org.cloudsmith.geppetto.ruby.jrubyparser.JRubyparserUtils.java
/** * Reads the root content of the Node's source file and returns it as a string. * Returns null on failure to read the content. * //from w ww. java 2 s .c o m * @param n * @return */ public static String rootContent(Node n) { SourcePosition p = n.getPosition(); File f = new File(p.getFile()); try { return Files.toString(f, Charsets.UTF_8); } catch (IOException e) { return null; } }
From source file:com.threecrowd.scrapi.ConfigReader.java
@SuppressWarnings({ "AssignmentToNull" }) static String ReadFile(@NotNull final String filename) throws Exception { return Files.toString(new File(filename), Charset.defaultCharset()); }
From source file:google.registry.tools.CreateOrUpdatePremiumListCommandTestCase.java
static String generateInputData(String premiumTermsPath) throws Exception { return Files.toString(new File(premiumTermsPath), StandardCharsets.UTF_8); }
From source file:com.carmatech.maven.model.MergerTestUtils.java
public static <T> String readExpectedProperties(final String name, final Class<T> clazz) throws IOException { return Files.toString(new File(name), UTF_8).replace("${merger}", clazz.getSimpleName()); }