List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
From source file:me.ryandowling.allmightybot.commands.SongCommand.java
@Override public boolean run(AllmightyBot bot, MessageEvent event) { if (super.run(bot, event)) { String song = "Unknown"; String artist = "Unknown"; String website = "Unknown"; try {/*ww w . j av a2 s .c o m*/ String playing = FileUtils.readFileToString(Utils.getNowPlayingFile().toFile()); song = playing.substring(playing.lastIndexOf("-") + 2); artist = playing.substring(0, playing.lastIndexOf("-") - 1); String songPath = FileUtils.readFileToString(Utils.getNowPlayingFileFile().toFile()); if (songPath.contains("\\")) { songPath = songPath.substring(0, songPath.lastIndexOf("\\")); } else { songPath = songPath.substring(0, songPath.lastIndexOf("/")); } website = FileUtils.readFileToString(new File(songPath, "website.txt")); } catch (IOException e) { e.printStackTrace(); } event.getChannel().send().message( Utils.replaceVariablesInString(bot.getLangValue("currentSong"), song, artist, website)); return true; } return false; }
From source file:gov.nih.nci.cabig.caaers.testdata.TestDataFileUtils.java
/** * Return the content of the file/* w w w.ja v a 2s. co m*/ * @param f * @return */ public static String getContent(File f) throws Exception { return FileUtils.readFileToString(f); }
From source file:edu.illinois.cs.cogcomp.question_typer.QuestionTyperFeatureExtractorsUtils.java
private static HashSet<String> readFileAsSet(String filePath) { String fileContents = null;/*from ww w .ja v a 2 s. c o m*/ try { fileContents = FileUtils.readFileToString(new File(filePath)); } catch (IOException e) { e.printStackTrace(); } String[] strs = fileContents.split("\n"); return new HashSet<>(Arrays.asList(strs)); }
From source file:com.bna.ezrxlookup.unit.util.JsonMapperUtilTest.java
@Test public void parseOpenFdaResponseResults() { String response = ""; List<DrugReaction> resultSet; try {/*w w w . j a v a2 s . c o m*/ File file = new File(getUserDir() + EVENT_SAMPLE_FILE); response = FileUtils.readFileToString(file); } catch (IOException e1) { LOG.error(e1); } // expect successful test try { resultSet = JsonMapperUtil.readJsonToList(response, RESULTS_NODE, DrugReaction.class); for (DrugReaction result : resultSet) LOG.debug("parseOpenFdaResponseResults: " + result); } catch (Exception e) { LOG.error(e); } // expect failed test try { resultSet = JsonMapperUtil.readJsonToList(response, "result", DrugReaction.class); for (DrugReaction result : resultSet) LOG.debug("parseOpenFdaResponseResults: " + result); } catch (Exception e) { LOG.error(e); } }
From source file:com.evanzeimet.queryinfo.QueryInfoTestUtils.java
public static String getFormattedJson(Class<?> clazz, String filename) throws IOException, QueryInfoException { URL url = clazz.getResource(filename); if (url == null) { String message = String.format("Resource not found at [%s]", filename); throw new QueryInfoException(message); }/*from w ww.j a v a2 s.c om*/ File file = new File(url.getPath()); String rawContents = FileUtils.readFileToString(file); return dosToUnix(rawContents); }
From source file:gov.nih.nci.cacis.common.schematron.SchematronValidatorTest.java
/** * checks xsd validation with valid xml//from www. j av a 2 s.co m * @throws IOException - exception thrown if any */ @Test public void validateValidXML() throws IOException { final String validXmlFile = getClass().getClassLoader().getResource("schematron-test.xml").getFile(); final String xmlString = FileUtils.readFileToString(new File(validXmlFile)); Assert.assertNotNull(xmlString); final String output = validator.validate(xmlString); Assert.assertNotNull(output); Assert.assertEquals("", output); }
From source file:edu.cuhk.hccl.Indexer.java
/** * Create index of RAMDirectory from a data folder with text files * /*from w w w . j a va 2s . c o m*/ * @param dataSet * @throws IOException */ public static void createIndex(String dataSet) throws IOException { IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, analyzer); IndexWriter writer = new IndexWriter(index, config); Collection<File> files = FileUtils.listFiles(new File(dataSet), null, true); for (File file : files) { String path = file.getPath(); String content = FileUtils.readFileToString(file); Document doc = new Document(); doc.add(new StringField(PATH_FIELD, path, Field.Store.YES)); doc.add(new Field(CONTENT_FIELD, content, TERM_STORED)); writer.addDocument(doc); System.out.println("[INFO] Indexing file: " + path); } System.out.println("\n[INFO]" + files.size() + " files has been indexed."); writer.close(); }
From source file:com.github.mgramin.sqlboot.model.resource_type.impl.composite.md.MarkdownFileTest.java
@Test public void parse() throws IOException { String text = FileUtils.readFileToString(new File("test.md")); MarkdownFile markdownFile = new MarkdownFile(text); Map<String, String> parse = markdownFile.parse(); System.out.println(parse);//w w w. j av a 2 s .c o m }
From source file:ee.ioc.cs.vsle.parser.JavaFileSourceProvider.java
protected String getStringFromFile(String pathname) { File file = new File(pathname); try {//from w ww .j a v a 2 s . c om return FileUtils.readFileToString(file); } catch (Exception e) { throw new SpecificationNotFoundException("Specification source not found in " + pathname); } }
From source file:hu.bme.mit.trainbenchmark.benchmark.neo4j.checkers.Neo4jCypherChecker.java
protected Neo4jCypherChecker(final Neo4jDriver driver, final BenchmarkConfig bc) throws IOException { super();/*from ww w . j ava2s. c o m*/ this.driver = driver; query = bc.getQuery(); queryDefinition = FileUtils.readFileToString(new File( bc.getWorkspacePath() + "/hu.bme.mit.trainbenchmark.benchmark.neo4j/src/main/resources/queries/" + bc.getQuery() + ".cypher")); }