try { if (!file1.exists() || !file2.exists()) { System.out.println("One or both files do not exist:" + name1 + ", " + name2); return false; } if (file1.length() != file2.length()) { System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " + name2 + "(" + file2.length() + ")"); return false; } // byte - byte compare byte[] buffer1 = new byte[BUF_SIZE]; byte[] buffer2 = new byte[BUF_SIZE]; FileInputStream fis1 = new FileInputStream(file1); FileInputStream fis2 = new FileInputStream(file2); int index = 0; int read = 0; while ((read = fis1.read(buffer1)) != -1) { fis2.read(buffer2); for (int i = 0; i < read; ++i, ++index) { if (buffer1[i] != buffer2[i]) { System.out.println("Bytes mismatch:" + name1 + ", " + name2 + " at byte " + index); return false; } } } return true; } catch (IOException e) { System.out.println("IOException comparing files: " + name1 + ", " + name2); return false; }
try { if (!file1.exists() || !file2.exists()) { System.out.println("One or both files do not exist:" + name1 + ", " + name2); return false; } if (file1.length() != file2.length()) { System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " + name2 + "(" + file2.length() + ")"); return false; } // byte - byte compare byte[] buffer1 = new byte[BUF_SIZE]; byte[] buffer2 = new byte[BUF_SIZE]; FileInputStream fis1 = new FileInputStream(file1); FileInputStream fis2 = new FileInputStream(file2); int index = 0; int read = 0; while ((read = fis1.read(buffer1)) != -1) { fis2.read(buffer2); for (int i = 0; i < read; ++i, ++index) { if (buffer1[i] != buffer2[i]) { System.out.println("Bytes mismatch:" + name1 + ", " + name2 + " at byte " + index); return false; } } } return true; } catch (IOException e) { System.out.println("IOException comparing files: " + name1 + ", " + name2); return false; }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
Method name: boolean compareFiles(String, String) Method name: boolean compareFiles(String, String)
Number of AST nodes: 20 Number of AST nodes: 20
1
try {
1
try {
2
            if (!file1.exists() || !file2.exists()) {
2
            if (!file1.exists() || !file2.exists()) {
3
                System.out.println("One or both files do not exist:" + name1 + ", " + name2);
3
                System.out.println("One or both files do not exist:" + name1 + ", " + name2);
4
                return false;
4
                return false;
5
            }
5
            }
6
            if (file1.length() != file2.length()) {
6
            if (file1.length() != file2.length()) {
7
                System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +
7
                System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +
8
                                   name2  + "(" + file2.length() + ")");
8
                                   name2  + "(" + file2.length() + ")");
9
                return false;
9
                return false;
10
            }
10
            }
11
            // byte - byte compare
11
            // byte - byte compare
12
            byte[] buffer1 = new byte[BUF_SIZE];
12
            byte[] buffer1 = new byte[BUF_SIZE];
13
            byte[] buffer2 = new byte[BUF_SIZE];
13
            byte[] buffer2 = new byte[BUF_SIZE];
14
            FileInputStream fis1 = new FileInputStream(file1);
14
            FileInputStream fis1 = new FileInputStream(file1);
15
            FileInputStream fis2 = new FileInputStream(file2);
15
            FileInputStream fis2 = new FileInputStream(file2);
16
            int index = 0;
16
            int index = 0;
17
            int read = 0;
17
            int read = 0;
18
            while ((read = fis1.read(buffer1)) != -1) {
18
            while ((read = fis1.read(buffer1)) != -1) {
19
                fis2.read(buffer2);
19
                fis2.read(buffer2);
20
                for (int i = 0; i < read; ++i, ++index) {
20
                for (int i = 0; i < read; ++i, ++index) {
21
                    if (buffer1[i] != buffer2[i]) {
21
                    if (buffer1[i] != buffer2[i]) {
22
                        System.out.println("Bytes mismatch:" + name1 + ", " + name2 +
22
                        System.out.println("Bytes mismatch:" + name1 + ", " + name2 +
23
                                           " at byte " + index);
23
                                           " at byte " + index);
24
                        return false;
24
                        return false;
25
                    }
25
                    }
26
                }
26
                }
27
            }
27
            }
28
            return true;
28
            return true;
29
        }
29
        }
30
        catch (IOException e) {
30
        catch (IOException e) {
31
            System.out.println("IOException comparing files: " + name1 + ", " + name2);
31
            System.out.println("IOException comparing files: " + name1 + ", " + name2);
32
            return false;
32
            return false;
33
        }
33
        }
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)1.7
Clones locationClones are in different classes having the same super class
Number of node comparisons107
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements20
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)6.8
    Clone typeType 1
    Mapped Statements
    ID Statement ID Statement
    3
    try
    3
    try
    4
    if (!file1.exists() || !file2.exists())
    4
    if (!file1.exists() || !file2.exists())
    5
    System.out.println("One or both files do not exist:" + name1 + ", " + name2);
    5
    System.out.println("One or both files do not exist:" + name1 + ", " + name2);
    6
    return false;
    6
    return false;
    7
    if (file1.length() != file2.length())
    7
    if (file1.length() != file2.length())
    8
    System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " + name2 + "(" + file2.length() + ")");
    8
    System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " + name2 + "(" + file2.length() + ")");
    9
    return false;
    9
    return false;
    10
    byte[] buffer1 = new byte[BUF_SIZE];
    10
    byte[] buffer1 = new byte[BUF_SIZE];
    11
    byte[] buffer2 = new byte[BUF_SIZE];
    11
    byte[] buffer2 = new byte[BUF_SIZE];
    12
    FileInputStream fis1 = new FileInputStream(file1);
    12
    FileInputStream fis1 = new FileInputStream(file1);
    13
    FileInputStream fis2 = new FileInputStream(file2);
    13
    FileInputStream fis2 = new FileInputStream(file2);
    14
    int index = 0;
    14
    int index = 0;
    15
    int read = 0;
    15
    int read = 0;
    16
    while ((read = fis1.read(buffer1)) != -1)
    16
    while ((read = fis1.read(buffer1)) != -1)
    17
    fis2.read(buffer2);
    17
    fis2.read(buffer2);
    18
    for (int i = 0; i < read; ++i, ++index)
    18
    for (int i = 0; i < read; ++i, ++index)
    19
    if (buffer1[i] != buffer2[i])
    19
    if (buffer1[i] != buffer2[i])
    20
    System.out.println("Bytes mismatch:" + name1 + ", " + name2 + " at byte " + index);
    20
    System.out.println("Bytes mismatch:" + name1 + ", " + name2 + " at byte " + index);
    21
    return false;
    21
    return false;
    22
    return true;
    22
    return true;
    Precondition Violations (0)
    Row Violation