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.PrintNRTest.java
@Test public void testSamplePrintNR() throws Exception { runConfor();/*from w w w. ja v a 2 s . c o m*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/names.rtf")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "rtf/names.rtf")); 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. 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, actual); }
From source file:au.org.ala.delta.confor.SummaryTest.java
@Test public void testSampleSummary() throws Exception { runConfor();/*from w w w . ja v a 2 s. c om*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/summary.prt")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "summary.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 15:43 28-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; } } //assertEquals(expected.trim(), actual.trim()); }
From source file:au.org.ala.delta.confor.PrintIRTest.java
@Test public void testSamplePrintIR() throws Exception { runConfor();//from w w w .ja va 2 s. c om File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/items.rtf")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "rtf/items.rtf")); 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. 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, actual); }
From source file:au.org.ala.delta.confor.PrintCTest.java
@Test public void testSamplePrintC() throws Exception { runConfor();//from ww w . j a va 2 s.co m File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/printc.prt")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "printc.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:au.org.ala.delta.confor.PrintNTest.java
@Test public void testSamplePrintN() throws Exception { runConfor();/*from w w w. j a v a2s.co m*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/printn.prt")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "printn.prt")); 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 16:11 11-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:com.joyent.manta.client.multipart.TestMultipartManagerTest.java
public void canDoMultipartUpload() throws IOException { TestMultipartUpload upload = manager.initiateUpload("/user/stor/testobject"); MantaMultipartUploadPart[] parts = new MantaMultipartUploadPart[] { manager.uploadPart(upload, 1, "Line 1\n"), manager.uploadPart(upload, 2, "Line 2\n"), manager.uploadPart(upload, 3, "Line 3\n"), manager.uploadPart(upload, 4, "Line 4\n"), manager.uploadPart(upload, 5, "Line 5") }; Stream<MantaMultipartUploadTuple> partsStream = Stream.of(parts); manager.complete(upload, partsStream); String actual = FileUtils.readFileToString(upload.getContents(), StandardCharsets.UTF_8); String expected = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5"; Assert.assertEquals(actual, expected); }
From source file:au.org.ala.delta.confor.ToNatRTest.java
@Test public void testSampleToNatR() throws Exception { runConfor();//from ww w.j a v a 2 s. co m File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/descrip.rtf")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "rtf/descrip.rtf")); 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")); } actual = actual.replaceAll("\\{\\} ", "\\{\\}"); expected = expected.replaceAll("\\{\\} ", "\\{\\}"); actual = actual.replaceAll(" \\\\", "\\\\"); expected = expected.replaceAll(" \\\\", "\\\\"); // The heading contains the date so will be different. 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, actual); }
From source file:au.org.ala.delta.confor.PrintCHTest.java
@Test public void testSamplePrintCH() throws Exception { runConfor();// www. j a v a 2 s.co m File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/chars.htm")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "www/chars.htm")); 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")); } // This is because StringEscapeUtils.escapeHtml has already done the // character conversion for left and right quotes. this makes the //line wrapping not match. actual = actual.replace("&lsquo", "‘"); actual = actual.replace("&rsquo", "’"); actual = actual.replace("&ndash", "–"); // The heading contains the date so will be different. 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, actual); }
From source file:au.org.ala.delta.confor.PrintUncodedTest.java
@Test public void testSamplePrintUncoded() throws Exception { runConfor();/* w w w. ja v a 2 s.c o m*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/uncoded.prt")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "uncoded.prt")); 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: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:au.org.ala.delta.confor.ToNatRPoneriniTest.java
@Test public void testSampleToNatR() throws Exception { runConfor();/*from w w w . ja v a 2 s .c o m*/ File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/descrip.rtf")); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(_samplePath, "rtf/descrip.rtf")); 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")); } actual = actual.replaceAll("\\{\\} ", "\\{\\}"); expected = expected.replaceAll("\\{\\} ", "\\{\\}"); actual = actual.replaceAll(" \\\\", "\\\\"); expected = expected.replaceAll(" \\\\", "\\\\"); // The heading contains the date so will be different. 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, actual); }