List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file, String encoding) throws IOException
From source file:au.org.ala.delta.confor.ToPaupTest.java
@Test public void testSampleToPaup() throws Exception { runConfor();//from www . j av a 2s .com File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/paupdata")); String expected = FileUtils.readFileToString(expectedFile, "utf-8"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "paupdata")); String actual = FileUtils.readFileToString(actualFile, "utf-8"); System.out.print(actual); boolean dosEol = expected.contains("\r\n"); String expectedLineSeparator = "\n"; if (dosEol) { expectedLineSeparator = "\r\n"; } if (!System.getProperty("line.separator").equals(expectedLineSeparator)) { expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator")); } // The heading contains the date so will be different. String heading = "Grass Genera 15:43 22-OCT-11"; // <Date>, eg. 11:32 05-OCT-11 actual = actual.replaceAll("Grass Genera.*[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}", heading); /*for (int i=0; i<expected.length(); i++) { if (expected.charAt(i) != actual.charAt(i)) { System.out.println("Difference @ char: "+i+" Expected: "+expected.charAt(i)+(int)expected.charAt(i)+", Actual: "+actual.charAt(i)+(int)actual.charAt(i)); break; } } BufferedReader expectedReader = new BufferedReader(new StringReader(expected)); BufferedReader actualReader = new BufferedReader(new StringReader(actual)); String expectedLine = expectedReader.readLine(); String actualLine = actualReader.readLine(); while (expectedLine != null) { assertEquals(expectedLine.trim(), actualLine.trim()); expectedLine = expectedReader.readLine(); actualLine = actualReader.readLine(); }*/ assertEquals(expected.trim(), actual.trim()); }
From source file:au.org.ala.delta.confor.ToHenningTest.java
@Test public void testSampleToHenning86() throws Exception { runConfor();//from www . j a v a 2s .com File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/hendata")); String expected = FileUtils.readFileToString(expectedFile, "utf-8"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "hendata")); String actual = FileUtils.readFileToString(actualFile, "utf-8"); System.out.print(actual); boolean dosEol = expected.contains("\r\n"); String expectedLineSeparator = "\n"; if (dosEol) { expectedLineSeparator = "\r\n"; } if (!System.getProperty("line.separator").equals(expectedLineSeparator)) { expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator")); } // The heading contains the date so will be different. String heading = "Grass Genera 11:53 15-NOV-11"; // <Date>, eg. 11:32 05-OCT-11 actual = actual.replaceAll("Grass Genera.*[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}", heading); /*for (int i=0; i<expected.length(); i++) { if (expected.charAt(i) != actual.charAt(i)) { System.out.println("Difference @ char: "+i+" Expected: "+expected.charAt(i)+(int)expected.charAt(i)+", Actual: "+actual.charAt(i)+(int)actual.charAt(i)); break; } } BufferedReader expectedReader = new BufferedReader(new StringReader(expected)); BufferedReader actualReader = new BufferedReader(new StringReader(actual)); String expectedLine = expectedReader.readLine(); String actualLine = actualReader.readLine(); while (expectedLine != null) { assertEquals(expectedLine.trim(), actualLine.trim()); expectedLine = expectedReader.readLine(); actualLine = actualReader.readLine(); }*/ assertEquals(expected.trim(), actual.trim()); }
From source file:au.org.ala.delta.confor.TranslateUncodedTest.java
@Test public void testSampleTranslateUncoded() throws Exception { runConfor();// w w w . ja v a2s .c o m File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/translateuncoded.prt")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "translateuncoded.prt")); String actual = FileUtils.readFileToString(actualFile, "cp1252"); System.out.print(actual); boolean dosEol = expected.contains("\r\n"); String expectedLineSeparator = "\n"; if (dosEol) { expectedLineSeparator = "\r\n"; } if (!System.getProperty("line.separator").equals(expectedLineSeparator)) { expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator")); } // The heading contains the date so will be different. String heading = "Grass Genera 11:32 05-OCT-11"; // <Date>, eg. 11:32 05-OCT-11 actual = actual.replaceAll("Grass Genera.*[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}", heading); for (int i = 0; i < expected.length(); i++) { if (expected.charAt(i) != actual.charAt(i)) { System.out.println("Difference @ char: " + i + " Expected: " + expected.charAt(i) + (int) expected.charAt(i) + ", Actual: " + actual.charAt(i) + (int) actual.charAt(i)); break; } } assertEquals(expected.trim(), actual.trim()); }
From source file:fr.lirmm.yamplusplus.yampponline.TestOaeiAlignment.java
@Test public void testOaeiAlignment() throws IOException, ClassNotFoundException, OWLOntologyStorageException, SAXException { String iamlRameauAlignment = FileUtils .readFileToString(new File("src/test/resources/iaml-rameau_valid_test.rdf"), "UTF-8"); boolean testExtractValid = false; YamFileHandler fileHandler = new YamFileHandler(); JSONObject parseOaeiJson = new JSONObject(); parseOaeiJson = fileHandler.parseOaeiAlignmentFormat(iamlRameauAlignment); JSONArray entities = (JSONArray) parseOaeiJson.get("entities"); // Look for a specific valid mapping to test if parsing worked for (int i = 0; i < entities.size(); i++) { JSONObject mappingJObject = (JSONObject) entities.get(i); if (mappingJObject.get("valid").equals("valid") && mappingJObject.get("entity1").equals("http://iflastandards.info/ns/unimarc/terms/mop/wdb") && mappingJObject.get("entity2").equals("http://data.bnf.fr/ark:/12148/cb12270245r")) { testExtractValid = true;/* w w w. java2 s . co m*/ break; } } //System.out.println(parseOaeiJson.toString()); assertTrue(testExtractValid); }
From source file:mitll.xdata.dataset.kiva.ingest.KivaIngest.java
public static Object[] processSchema(String filename) throws Exception { // teams:category: [String] // teams:image:id: [Integer] String schema = FileUtils.readFileToString(new File(filename), "UTF-8").trim(); List<String> names = new ArrayList<String>(); List<String> types = new ArrayList<String>(); String regex = "([a-zA-Z_0-9:\\[\\]]+):\\s+\\[([a-zA-Z_0-9]+)\\]"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(schema); while (matcher.find()) { String type = matcher.group(2).trim(); String name = matcher.group(1).trim(); // replace empty [] with nothing name = name.replaceAll("\\[\\]", ""); // strip off final colons name = name.replaceAll(":+$", ""); // replace internal ":" with "_" name = name.replaceAll(":+", "_"); names.add(name);/*from w ww . j ava 2s . c o m*/ types.add(type); } return new Object[] { names, types }; }
From source file:com.mindcognition.mindraider.utils.FileLoader.java
public void run() { try {//from w w w.j ava 2s .co m doc.setText(FileUtils.readFileToString(file, "UTF-8")); } catch (IOException e) { if (logger.isDebugEnabled()) { logger.debug("run(): " + e.getMessage()); } } }
From source file:com.mtt.myapp.operation.service.SystemConfigService.java
/** * Get system configuration file content. * * @return file content.//from w w w . j a va2 s . c o m */ public String getOne() { try { return FileUtils.readFileToString(home.getSubFile("system.conf"), "UTF-8"); } catch (Exception e) { LOG.error("Error while reading system configuration file."); return null; } }
From source file:com.thoughtworks.go.config.IdFileService.java
public String load() { try {// w w w. j a v a2s. c om return FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim(); } catch (IOException ioe) { throw bomb(String.format("Couldn't load %s from filesystem", file.getName()), ioe); } }
From source file:com.haulmont.cuba.core.sys.javacl.SourceProvider.java
public String getSourceString(String name) throws IOException { File srcFile = getSourceFile(name); if (!srcFile.exists()) { throw new FileNotFoundException(String.format("Java source for %s not found", name)); }/*from w w w .j a v a2 s .co m*/ return FileUtils.readFileToString(srcFile, StandardCharsets.UTF_8); }
From source file:eshore.cn.it.phrase.TestPhrase.java
public void testSeg() throws Exception { System.out.println(StandardTokenizer.segment(FileUtils.readFileToString( new File(FOLDER + "\\??4000.txt"), "GBK"))); }