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.cognifide.aet.executor.xmlparser.xml.XmlTestSuiteParser.java
@Override public TestSuiteRun parse(File testSuiteFile) throws ParseException { try {/*from www . j ava 2 s.c om*/ String testSuiteString = Files.toString(testSuiteFile, Charsets.UTF_8); return parse(testSuiteString); } catch (IOException e) { throw new ParseException(e.getMessage(), e); } }
From source file:org.jboss.pnc.ocleaner.ejb.ScheduleCleanup.java
@PostConstruct public void init() { String tokenFile = config.getTokenFile(); String tokenContent = null;//from w w w .ja va2 s . com try { tokenContent = Files.toString(new File(tokenFile), Charsets.UTF_8); } catch (IOException e) { LOGGER.warning("Could not read from file: " + tokenFile); } oclient = new OpenshiftClient(config.getOSEServer(), tokenContent); }
From source file:eu.numberfour.n4js.antlr.internal.AntlrCodeQualityHelper.java
/** * Remove duplicate bitset declarations to reduce the size of the static initializer but keep the bitset * FOLLOW_ruleExpression_in_ruleExpressionStatement with a simplified name. *//*from w w w .j a v a 2 s. c o m*/ public static void removeDuplicateBitsets(String javaFile, Charset encoding) { try { // String content = Files.toString(new File(javaFile), encoding); StringBuilder newContent = new StringBuilder(content.length()); Matcher matcher = bitsetPattern.matcher(content); int offset = 0; Map<String, String> bitsets = Maps.newHashMap(); Map<String, String> namesToReplace = Maps.newHashMap(); while (matcher.find(offset)) { String originalFieldName = matcher.group(1); String synthesizedFieldName = "FOLLOW_" + (bitsets.size() + 1); String bitset = matcher.group(2); String existing = bitsets.putIfAbsent(bitset, synthesizedFieldName); if (existing == null) { existing = synthesizedFieldName; newContent.append(content, offset, matcher.start(1)); newContent.append(synthesizedFieldName); newContent.append(" = "); newContent.append(bitset); } namesToReplace.put(originalFieldName, existing); if (originalFieldName.startsWith("FOLLOW_ruleExpression_in_ruleExpressionStatement")) { newContent.append(content, offset, matcher.start(1)); newContent.append("FOLLOW_ruleExpression_in_ruleExpressionStatement = "); newContent.append(existing); } offset = matcher.end(2); } newContent.append(content, offset, content.length()); content = newContent.toString(); newContent = new StringBuilder(content.length()); String rawFollowPattern = "\\bFOLLOW_\\w+\\b"; Pattern followPattern = Pattern.compile(rawFollowPattern); Matcher followMatcher = followPattern.matcher(content); Set<String> doNotReplace = Sets.newHashSet(bitsets.values()); doNotReplace.add("FOLLOW_ruleExpression_in_ruleExpressionStatement"); offset = 0; while (followMatcher.find(offset)) { String replaceMe = followMatcher.group(); String replaceBy = namesToReplace.get(replaceMe); if (replaceBy == null) { if (!doNotReplace.contains(replaceMe)) throw new IllegalStateException(replaceMe); replaceBy = replaceMe; } newContent.append(content, offset, followMatcher.start()); newContent.append(replaceBy); offset = followMatcher.end(); } newContent.append(content, offset, content.length()); Files.write(newContent, new File(javaFile), encoding); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:eu.numberfour.n4js.antlr.AntlrToolFacadeWithInjectedCode.java
private void injectCode(String grammarFullPath) { try {/*from w w w .j a v a2s. com*/ String grammarContent = Files.toString(new File(grammarFullPath), Charsets.UTF_8); if (grammarFullPath.endsWith("Lexer.g")) { grammarContent = processLexerGrammar(grammarContent); } else if (grammarFullPath.endsWith("Parser.g")) { grammarContent = processParserGrammar(grammarContent); } else { throw new IllegalArgumentException(grammarFullPath); } Files.write(grammarContent, new File(grammarFullPath), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(); } }
From source file:io.prestosql.benchmark.driver.BenchmarkQuery.java
public BenchmarkQuery(File file) throws IOException { requireNonNull(file, "file is null"); name = Files.getNameWithoutExtension(file.getName()); // file can have 2 sections separated by a line of equals signs String text = Files.toString(file, StandardCharsets.UTF_8); List<String> sections = SECTION_SPLITTER.splitToList(text); if (sections.size() == 2) { this.tags = ImmutableMap.copyOf(TAGS_SPLITTER.split(sections.get(0))); this.sql = sections.get(1); } else {/* w w w . j a v a2 s . c om*/ // no tags this.tags = ImmutableMap.of(); this.sql = sections.get(0); } }
From source file:ezbake.endpoint.web.LogsServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Properties configuration = BaseClient.getInstance().getConfiguration(); SystemConfigurationHelper sysConfig = new SystemConfigurationHelper(configuration); EzBakeApplicationConfigurationHelper appConf = new EzBakeApplicationConfigurationHelper(configuration); response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); writer.println(Files.toString( new File(sysConfig.getLogFilePath(appConf.getApplicationName(), appConf.getServiceName())), Charset.defaultCharset())); }
From source file:org.apache.drill.hbase.HBaseTestsSuite.java
public static String getPlanText(String planFile) throws IOException { String text = Files.toString(FileUtils.getResourceAsFile(planFile), Charsets.UTF_8); return text.replaceFirst("\"zookeeperPort\".*:.*\\d+", "\"zookeeperPort\" : " + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT)); }
From source file:co.signal.loadgen.LoadGenerator.java
private static @Nullable String readFile(String filename) { try {// w ww .j a va 2 s. c om return Files.toString(new File(filename), Charsets.UTF_8); } catch (IOException e) { log.warn("Unable to retrieve config from " + filename, e); return null; } }
From source file:com.google.api.codegen.MultiYamlReader.java
@Nullable public static Message read(DiagCollector collector, List<File> files, Map<String, Message> supportedConfigTypes) { List<String> inputNames = new ArrayList<>(); List<String> inputs = new ArrayList<>(); for (File file : files) { inputNames.add(file.getName());/*ww w . j a v a 2s . co m*/ try { String fileContent = Files.toString(file, Charset.forName("UTF8")); inputs.add(fileContent); } catch (IOException e) { collector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Cannot read configuration file '%s': %s", file.getName(), e.getMessage())); } } if (collector.getErrorCount() > 0) { return null; } else { return read(collector, inputNames, inputs, supportedConfigTypes); } }
From source file:com.google.devtools.moe.client.project.FileReadingProjectContextFactory.java
@Override public ProjectConfig loadConfiguration(String configFilename) throws InvalidProject { String configText;/*w w w . jav a2s . c o m*/ Ui.Task task = ui.pushTask("read_config", "Reading config file from %s", configFilename); try { try { configText = Files.toString(new File(configFilename), UTF_8); } catch (IOException e) { throw new InvalidProject("Config File \"" + configFilename + "\" not accessible."); } return ProjectConfig.parse(configText); } finally { ui.popTask(task, ""); } }