List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:pl.edu.icm.coansys.heeut.TestMapReduce.java
@Test(timeout = 1800000) public void testWordCountDiff() throws Exception { String prefix = getCurrentDateAppended("wordcount"); String inputDirName = prefix + "-input"; String outputDirName = prefix + "-output"; FileSystem dfs = UTIL.getDFSCluster().getFileSystem(); Path inputDir = new Path(inputDirName); Path qualifiedInputDir = dfs.makeQualified(inputDir); String inputFileName = "src/test/resource/input/wordcount/apache_projects.dat"; dfs.copyFromLocalFile(new Path(inputFileName), qualifiedInputDir); ToolRunner.run(UTIL.getConfiguration(), new WordCount(), new String[] { inputDirName, outputDirName }); Path outputDir = new Path(outputDirName); Path qualifiedOutputDir = dfs.makeQualified(outputDir); String localOutputDir = "src/test/resource/output/wordcount/" + prefix; dfs.copyToLocalFile(qualifiedOutputDir, new Path(localOutputDir)); File outputFile = new File(localOutputDir + "/part-00000"); File expectedFile = new File("src/test/resource/exp/wordcount/apache_projects.exp"); boolean isEqual = FileUtils.contentEquals(outputFile, expectedFile); Assert.assertTrue(isEqual);/*from w w w . j a va2s.c o m*/ }
From source file:se.inera.axel.test.st2.TS1_IT.java
/** * TS1a - Send a ping request to a remote shs server via the local server. * * <p/>/*from w ww . j a v a 2s .co m*/ * Sends {@link #FILE_PING_REQUEST_OK} synchronously with product @{link #PRODUCT_TEST_0} * from {@link #ACTOR_AXEL} to {@link #ACTOR_REFERENCE}. * * <p/> * The request should succeed and the response should be a mirror of the request. * * @throws Throwable */ @Test public void testTS1a() throws Throwable { String[] args = { "request", "-f", ACTOR_AXEL, "-t", ACTOR_REFERENCE, "-p", PRODUCT_TEST_0, "-in", FILE_PING_REQUEST_OK_BODY.getAbsolutePath(), "-out", FILE_TEST_OUT.getAbsolutePath() }; ShsCmdline.main(args); Assert.assertTrue(FileUtils.contentEquals(FILE_TEST_OUT, FILE_PING_REQUEST_OK_BODY), "Response from ping request does not match expected response: response " + FileUtils.readFileToString(FILE_TEST_OUT)); }
From source file:test.bgp.AnalyzeResults.java
/** * //from www. j av a 2 s. c om */ public void resultsComparator() { for (int i = 0; i < resultFile.size(); i += 2) { try { logger.info(resultFile.get(i) + " ?? " + resultFile.get(i + 1)); queryComparator.put(queriesName.get(i / 2), FileUtils.contentEquals(resultFile.get(i), resultFile.get(i + 1))); } catch (IOException ex) { LogManager.getLogger(AnalyzeResults.class.getName()).log(Level.ERROR, "", ex); } } for (String s : queriesName) { logger.info("Query \"" + s + "\": same results Default VS Hybrid ? ===> " + queryComparator.get(s).toString().toUpperCase()); } }
From source file:test.FileAssertions.java
private static void doBinaryFileComparison(String fixture, String output) throws IOException { File fixtureFile = new File(fixture); File outputFile = new File(output); assertTrue(FileUtils.contentEquals(fixtureFile, outputFile)); }
From source file:tokyo.northside.omegat.markdown.TestFilterBase.java
protected void translateText(IFilter filter, String resource, Map<String, String> config) throws Exception { translate(filter, resource, config); boolean result = FileUtils.contentEquals(new File(this.getClass().getResource(resource).getFile()), outFile);/* ww w .j av a 2 s .co m*/ if (!result) { List<String> origin = IOUtils.readLines( FileUtils.openInputStream(new File(this.getClass().getResource(resource).getFile()))); List<String> lines = IOUtils.readLines(FileUtils.openInputStream(outFile)); if (origin.size() != lines.size()) { fail("Differ a number of lines. Original:" + origin.size() + ", outFile: " + lines.size()); } assertEquals(lines, origin, resource); } }
From source file:ubic.basecode.ontology.OntologyLoader.java
public static boolean hasChanged(String cacheName) { boolean changed = false; // default if (StringUtils.isBlank(cacheName)) { return changed; }//from ww w . j a v a 2 s .com File newFile = getDiskCachePath(cacheName); File oldFile = getOldDiskCachePath(cacheName); try { // This might be slow considering it calls IOUtils.contentsEquals which compares byte-by-byte // in the worst case scenario. // In this case consider using NIO for higher-performance IO using Channels and Buffers. // Ex. Use a 4MB Memory-Mapped IO operation. if (newFile != null && oldFile != null) changed = !FileUtils.contentEquals(newFile, oldFile); } catch (IOException e) { log.error(e.getMessage()); } return changed; }
From source file:uk.co.unclealex.executable.impl.MakeLinksCommandRunnerTest.java
protected void checkDirectoriesEqual(Path expectedDir, Path actualDir) throws IOException { Assert.assertTrue("Path " + expectedDir + "is not a directory.", Files.isDirectory(expectedDir, LinkOption.NOFOLLOW_LINKS)); Assert.assertTrue("Path " + actualDir + "is not a directory.", Files.isDirectory(actualDir, LinkOption.NOFOLLOW_LINKS)); Assert.assertArrayEquals("Directory " + actualDir + " has the wrong file entries.", filenamesIn(expectedDir), filenamesIn(actualDir)); DirectoryStream<Path> directoryStream = Files.newDirectoryStream(actualDir); for (Path expectedChild : directoryStream) { Path actualChild = expectedDir.resolve(expectedChild.getFileName()); if (Files.isDirectory(expectedChild, LinkOption.NOFOLLOW_LINKS)) { Assert.assertTrue("Path " + actualChild + " is not a directory.", Files.isDirectory(actualChild, LinkOption.NOFOLLOW_LINKS)); checkDirectoriesEqual(expectedChild, actualChild); } else if (Files.isSymbolicLink(expectedChild)) { Assert.assertTrue("Path " + actualChild + " is not a symbolic link", Files.isSymbolicLink(actualChild)); Assert.assertEquals("Symbolic link " + actualChild + " points to the wrong place.", Files.readSymbolicLink(expectedChild), Files.readSymbolicLink(actualChild)); } else {/* ww w .j a v a2 s. c o m*/ Assert.assertTrue("Path " + actualChild + " has the wrong content.", FileUtils.contentEquals(expectedChild.toFile(), actualChild.toFile())); } } }
From source file:utils.MigrateAttachments.java
@Override protected Integer doInBackground() throws Exception { ArrayList<String> fileNames = getFilesName(path); for (String s : fileNames) { //System.out.println("Checking " + s); long size = getFileSize(s); if (size > FILESIZELIMIT) { publish(bug.toString() + ": file " + s + " will not be transffered due to it size: " + size + " kb."); } else {/* ww w.j a v a 2 s. c o m*/ ArrayList<Attachments> attachments = MainController.getInstance().getByBugIdFilename(bug, s); if (!attachments.isEmpty()) { //publish(bug + " has " + attachments.size() + " attachments entries in DB.Checking if was already migrated!"); for (Attachments a : attachments) { String id = a.getAttachId().toString(); String groupId = "group." + id.substring(id.length() - 2); String fileId = "attachment." + id; try { File sourceFile = new File(path + "\\" + s); File destFile = new File(bugzillaPath + "attachments\\" + groupId + "\\" + fileId); if (!destFile.exists()) { //File defined in database but not present on disk. Cleanup to be performed publish("Attachment " + s + "/" + bug + " is present in DB(" + a.getAttachId() + ") but " + destFile.toString() + " is missing from disk. DB cleanup performed."); MainController.getInstance().deleteAttachments(a.getAttachId()); } if (FileUtils.contentEquals(destFile, sourceFile)) { publish(bug + " :" + s + " is present in DB(" + a.getAttachId() + ") and " + destFile.toString() + " is already present disk => already migrated"); } else { long startTime = new Date().getTime(); MainController.getInstance().migrateAttachment(s, path, bugzillaPath, bug, size); long elapsedTime = new Date().getTime() - startTime; publish(bug.toString() + ": file " + s + " (" + size + " kb) transffered in: " + elapsedTime / 1000 + "sec."); } } catch (Exception exp) { publish(exp.toString()); } } } else { long startTime = new Date().getTime(); MainController.getInstance().migrateAttachment(s, path, bugzillaPath, bug, size); long elapsedTime = new Date().getTime() - startTime; publish(bug.toString() + ": file " + s + " (" + size + " kb) transffered in: " + elapsedTime / 1000 + "sec."); } } } return bug.getBugId(); }
From source file:VASSAL.tools.io.IOUtilsTest.java
@Test public void testCopyFileChannels() throws IOException { final File ifile = new File("test/VASSAL/tools/io/IOUtilsTest.java"); final File ofile = new File("test/VASSAL/tools/io/test.out"); try {//w ww .java 2 s . c om final FileInputStream in = new FileInputStream(ifile); final FileOutputStream out = new FileOutputStream(ofile); final int count = IOUtils.copy(in, out); assertEquals(ifile.length(), count); assertTrue(FileUtils.contentEquals(ifile, ofile)); } finally { ofile.delete(); } }
From source file:VASSAL.tools.io.IOUtilsTest.java
@Test public void testCopyLargeFileChannels() throws IOException { final File ifile = new File("test/VASSAL/tools/io/IOUtilsTest.java"); final File ofile = new File("test/VASSAL/tools/io/test.out"); try {//from w w w . j a v a2 s . c o m final FileInputStream in = new FileInputStream(ifile); final FileOutputStream out = new FileOutputStream(ofile); final long count = IOUtils.copy(in, out); assertEquals(ifile.length(), count); assertTrue(FileUtils.contentEquals(ifile, ofile)); } finally { ofile.delete(); } }