Example usage for org.apache.commons.io FileUtils contentEquals

List of usage examples for org.apache.commons.io FileUtils contentEquals

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils contentEquals.

Prototype

public static boolean contentEquals(File file1, File file2) throws IOException 

Source Link

Document

Compares the contents of two files to determine if they are equal or not.

Usage

From source file:com.bysailors.comparefolders.compareFiles.java

public static boolean compareFiles(File File1, File File2) throws FileNotFoundException, IOException {
    if (!File1.exists() || !File2.exists())
        throw new FileNotFoundException("the file specified does not exists.");
    else/*from   www .  j  ava 2  s .  co  m*/
        return FileUtils.contentEquals(File1, File2);
}

From source file:com.oozierunner.core.FileManager.java

public static boolean contentEquals(String actualDataFileName, String expectedDataFileName) {

    File actualDataFile = new File(actualDataFileName);
    File expectedDataFile = new File(expectedDataFileName);

    if (!actualDataFile.exists()) {

        System.out.println("ActualDataFile :-> " + actualDataFileName + " : doesn't Exist...");
        return false;

    } else if (!expectedDataFile.exists()) {

        System.out.println("ExpectedDataFile :-> " + expectedDataFileName + " : doesn't Exist...");
        return false;

    }// w  w w . ja  v  a  2  s .  c  o  m

    boolean contentMatched = false;
    try {
        contentMatched = FileUtils.contentEquals(actualDataFile, expectedDataFile);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    return contentMatched;
}

From source file:info_teorija_1.Tests.java

public static void test(String fileIn, String fileOut, String fileRes) throws IOException {
    Stopwatch total = Stopwatch.createStarted();
    for (int i = 2; i <= 16; i++) {
        File in = new File(fileIn);
        File out = new File(fileOut);
        File res = new File(fileRes);

        System.out.println("Testing with " + i);

        Encode.clear();/*  w w  w .  j a  v  a2 s  .  c  o  m*/
        Decode.clear();
        HuffmanCode.clear();

        Stopwatch encode = Stopwatch.createStarted();
        Encode.encode(i, in, out);
        System.out.println("Encoding: " + encode.elapsed(TimeUnit.MILLISECONDS));
        encode.stop();
        Stopwatch decode = Stopwatch.createStarted();

        Decode.decode(out, res);
        System.out.println("Decoding: " + decode.elapsed(TimeUnit.MILLISECONDS));

        assertTrue(FileUtils.contentEquals(in, res));
        System.out.println("completed");
        out.delete();
        res.delete();
    }
    System.out.println("Total test: " + total.elapsed(TimeUnit.MILLISECONDS));
}

From source file:minecrunch_updater.Minecrunch_updater.java

private static void VersionCheck() throws MalformedURLException {

    // Get system properties
    String os = System.getProperty("os.name");
    String home = System.getProperty("user.home");
    String dir;/*from  ww w.  j av  a  2 s. c  om*/
    String newfile2 = null;

    if (os.contains("Windows")) {
        dir = home + "\\.minecrunch\\";
        newfile2 = dir + "\\resources\\";
    } else {
        dir = home + "/.minecrunch/";
        newfile2 = dir + "/resources/";
    }

    try {
        // Get version.txt from server
        URL url = new URL("http://www.minecrunch.net/download/minecrunch_installer/version.txt");
        File file = new File(dir + "version.txt");
        File file2 = new File(newfile2 + "version.txt");

        FileUtils.copyURLToFile(url, file);
        boolean isTwoEqual = FileUtils.contentEquals(file, file2);

        if (isTwoEqual) {
            System.out.println("Up to date.");
            Run();
        } else {
            Object[] options = { "Yes, please", "No way!" };
            Component frame = null;
            // Get answer if the user wants to update or not
            int n = JOptionPane.showOptionDialog(frame, "There is an update to Minecrunch Modpack.",
                    "Would you like to update now?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                    null, options, options[0]);

            if (n == JOptionPane.YES_OPTION) {
                // If yes run the Update method
                Update();
            } else {
                // If user chooses no then just run the minecrunch_launcher jar file
                Run();
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(Minecrunch_updater.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.ibm.watson.catalyst.corpus2json.Corpus2JsonTest.java

@Test
public void testMain() {
    Corpus2Json.main(new String[] { "sample/test.properties" });
    File file1 = new File("sample/test-check.json");
    File file2 = new File("sample/test-output.json");
    try {/*from w  ww. ja va 2 s .c o m*/
        assertTrue(FileUtils.contentEquals(file1, file2));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.CorpusTfidfTest.java

@Test
public void testMain() {
    CorpusTfidf.main(new String[] { "sample/test.properties" });
    File file1 = new File("sample/test-tfidf-check.json");
    File file2 = new File("sample/test-tfidf-output.json");
    try {/*w  w w.  jav  a  2 s.  c  om*/
        assertTrue(FileUtils.contentEquals(file1, file2));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:listduplicatingfiles.ListDuplicatingFiles.java

public boolean isDuplicated(List<File> list, File file) {
    for (File check : list) {
        try {//  w  ww .ja v  a2  s . c o  m
            if (FileUtils.contentEquals(check, file)) {
                return true;
            }
        } catch (IOException ex) {
            Logger.getLogger(ListDuplicatingFiles.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return false;
}

From source file:dremel.common.DremelParserTest.java

@Test
public void basic() throws RecognitionException, IOException {
    //tests parsing all SQL that are encountered in the documentation
    for (int i = 1; i <= 15; i++) {

        File tempFile = Drec.getFile("q" + i + "_temp.bql.ast");
        File expectedFile = Drec.getFile("q" + i + ".bql.ast");
        File queryFile = Drec.getFile("q" + i + ".bql");

        FileUtils.writeStringToFile(tempFile,
                DremelParser.parseBql(FileUtils.readFileToString(queryFile)).toStringTree());

        assertTrue("ast files differs", FileUtils.contentEquals(expectedFile, tempFile));

        FileUtils.forceDelete(tempFile);
    }//from w ww.  j av  a 2  s .c o  m
}

From source file:com.splunk.shuttl.testutil.TUtilsTestNG.java

/**
 * Asserts that the contents of specified files are equal. Failing the test
 * with specified message if not./*from w w w.j a v a 2  s  .c o m*/
 */
public static void assertFileContentsEqual(String message, File expected, File actual) {
    assertTrue(expected.toString() + " doesn't exist.", expected.exists());
    assertTrue(actual.toString() + " doesn't exist.", actual.exists());
    message = message == null ? "" : message;

    try {
        assertTrue(message, FileUtils.contentEquals(expected, actual));
    } catch (IOException e) {
        failForException("Can't compare contents of files.", e);
    }
}

From source file:cc.juch.btrfs_testsuite.IcatTest.java

@Test
public void icatTest() throws IOException, CliException {
    List<FileMetadata> testMetadata = PathUtil.createListing(testDataDir.toPath());
    List<FileMetadata> imageMetadata = Fls.getFiles(testImage);

    List<Pair<FileMetadata>> metadata = PathUtil.mergePaths(testMetadata, imageMetadata);

    assertTrue(metadata.size() > 0);/*w  ww.  j a  v a 2s  . c  om*/

    for (Pair<FileMetadata> p : metadata) {
        if (p.a.getFileType() == FileType.FILE) {
            LOG.info("compare metadata of testfile {} with icat output of inode {}",
                    p.a.getAbsolutePath().toString(), p.b.getInode());
            File f = Icat.getData(testImage, p.b.getInode()).getFile();
            assertTrue(FileUtils.contentEquals(p.a.getAbsolutePath().toFile(), f));
            f.delete();
        } else {
            LOG.info("skipping directory {}", p.a.getAbsolutePath());
        }
    }
}