List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file, String encoding) throws IOException
From source file:net.sf.jtmt.tokenizers.ParagraphTokenizer.java
/** * Instantiates a new paragraph tokenizer. * * @param rulesfile the rulesfile//from ww w. j a va 2s. com * @throws Exception the exception */ public ParagraphTokenizer(String rulesfile) throws Exception { super(); this.breakIterator = new RuleBasedBreakIterator( FileUtils.readFileToString(new File(getClass().getResource(rulesfile).getFile()), "UTF-8")); }
From source file:io.stallion.dataAccess.file.JsonFilePersister.java
public T doFetchOne(File file) { T o = null;/*www .j ava 2 s . co m*/ try { String json = FileUtils.readFileToString(file, UTF8); o = JSON.parse(json, this.getModelClass()); } catch (IOException e) { throw new RuntimeException(e); } return o; }
From source file:cat.calidos.morfeu.utils.FileSaverTest.java
@Test public void testSave() throws Exception { String tmp = setupTempDirectory(); //System.err.println("FileSaverTest::Using '"+tmp+"' as temporary test folder"); String path = tmp + "/filesaver-test-" + System.currentTimeMillis() + ".txt"; File file = new File(path); if (file.exists() && !file.isDirectory()) { file.delete();//from w w w. j ava 2 s . com } file.deleteOnExit(); String contentWritten = "foo"; FileSaver saver = new FileSaver(path, contentWritten); saver.save(); File file2 = new File(path); String contentRead = FileUtils.readFileToString(file2, Config.DEFAULT_CHARSET); assertEquals("Content written to the output file was not as expected", contentWritten, contentRead); }
From source file:au.org.ala.delta.confor.ToNexTest.java
/** * Because of ISSUE 66 the output from the original CONFOR has been * modified by chaning some inappicables to unknowns (and vice versa) * to allow this test to be run as a part of the build. *//*from w w w . j av a 2 s.co m*/ @Test public void testSampleToNex() throws Exception { runConfor(); File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/nexdata")); String expected = FileUtils.readFileToString(expectedFile, "utf-8"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "nexdata")); 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 14:43 20-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:com.talent.balance.conf.FrontendConf.java
/** * // ww w . j a va2 s .c om * @return */ public static FrontendConf getInstance() { if (instance == null) { synchronized (log) { if (instance == null) { try { instance = JsonWrap.toBean( FileUtils.readFileToString(new File("./conf/frontend-conf.json"), "utf-8"), FrontendConf.class); } catch (Exception e) { log.error("", e); throw new RuntimeException(e); } } } } return instance; }
From source file:de.dal33t.powerfolder.util.AddLicenseHeader.java
public static void addLicInfo(Path f) { try {//w w w. j a v a 2s . com if (f.toAbsolutePath().toString().contains("\\jwf\\jwf")) { System.out.println("Skip: " + f.toRealPath()); return; } if (f.toAbsolutePath().toString().contains("org\\jdesktop\\swinghelper")) { System.out.println("Skip: " + f.toRealPath()); return; } String content = FileUtils.readFileToString(f.toFile(), "UTF-8"); int i = content.indexOf("package"); // if (i != 693) { // System.out.println("Skip: " + f.getCanonicalPath() + ": " + i); // return; // } boolean dennis = content.contains("@author Dennis"); if (dennis) { System.err.println("Dennis: " + f.toRealPath() + ": " + i); content = LIC_INFO_DENNIS + content.substring(i, content.length()); } else { System.out.println("Onlyme: " + f.toRealPath() + ": " + i); content = LIC_INFO + content.substring(i, content.length()); } // // System.out.println(content); FileUtils.writeStringToFile(f.toFile(), content, "UTF-8"); // throw new RuntimeException(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:aiai.ai.utils.checksum.TestChecksumWithSignature.java
@Test public void test() throws IOException, GeneralSecurityException { File file = new File("config", "private-key.txt"); String base64 = FileUtils.readFileToString(file, StandardCharsets.UTF_8); PrivateKey privateKey = SecUtils.getPrivateKey(base64); String checksum = "69c33a60e09f00fa3610fb8833bef54487f9c8b99db48b339cd6ed0f192ba5c9"; String signature = SecUtils.getSignature(checksum, privateKey); String forVerifying = checksum + SecUtils.SIGNATURE_DELIMITER + signature; ChecksumWithSignatureService.ChecksumWithSignature checksumWithSignature = ChecksumWithSignatureService .parse(forVerifying);//from w w w. ja v a 2 s . c o m assertTrue(ChecksumWithSignatureService.isValid(checksumWithSignature.checksum.getBytes(), checksumWithSignature.signature, globals.publicKey)); }
From source file:com.thoughtworks.go.server.util.EncryptionHelperTest.java
@Test void shouldEncryptAndDecryptChunkUsingRSA() throws Exception { File privateKeyFile = new File( getClass().getClassLoader().getResource("rsa/subordinate-private.pem").getFile()); File publicKeyFile = new File( getClass().getClassLoader().getResource("rsa/subordinate-public.pem").getFile()); String chunk = "Encryption is Awesome!"; String encryptedChunk = EncryptionHelper.encryptUsingRSA(chunk, FileUtils.readFileToString(publicKeyFile, "utf8")); String decryptedChunk = EncryptionHelper.decryptUsingRSA(encryptedChunk, FileUtils.readFileToString(privateKeyFile, "utf8")); assertThat(decryptedChunk, is(chunk)); }
From source file:com.vilt.minium.prefs.AppPreferences.java
public AppPreferences(File file) throws IOException { this(FileUtils.readFileToString(file, Charsets.UTF_8.toString())); baseDir = file.getParentFile(); }
From source file:au.org.ala.delta.confor.FillinTest.java
protected void runAndTest(String resultFileName) throws Exception, IOException { runConfor();/*from www . ja va 2s . co m*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/" + resultFileName)); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, resultFileName)); 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")); } // CONFOR leaves a lot of trailing spaces around expected = expected.replaceAll(" ([\\r\\n]+)", "$1"); actual = actual.replaceAll(" ([\\r\\n]+)", "$1"); // The heading contains the date so will be different. String heading = "Grass Genera 13:32 12-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()); }