10-1-2

File file1 = new File(System.getProperty("root"), name1); File file2 = new File(System.getProperty("root"), name2); 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; }
File file1 = new File(System.getProperty("root"), name1); File file2 = new File(System.getProperty("root"), name2); 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/types/FilterSetTest.java |  | File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java
Method name: `boolean compareFiles(String, String)` |  | Method name: `boolean compareFiles(String, String)`
Number of AST nodes: 22 |  | Number of AST nodes: 22

1

    File file1 = new File(System.getProperty("root"), name1);↵

1

    File file1 = new File(System.getProperty("root"), name1);↵

2

            File file2 = new File(System.getProperty("root"), name2);↵

2

            File file2 = new File(System.getProperty("root"), name2);↵

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

                }↵

7

                }↵

8

                if (file1.length() != file2.length()) {↵

8

                if (file1.length() != file2.length()) {↵

9

                    System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +↵

9

                    System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " +↵

10

                                       name2  + "(" + file2.length() + ")");↵

10

                                       name2  + "(" + file2.length() + ")");↵

11

                    return false;↵

11

                    return false;↵

12

                }↵

12

                }↵

13

                // byte - byte compare↵

13

                // byte - byte compare↵

14

                byte[] buffer1 = new byte[BUF_SIZE];↵

14

                byte[] buffer1 = new byte[BUF_SIZE];↵

15

                byte[] buffer2 = new byte[BUF_SIZE];↵

15

                byte[] buffer2 = new byte[BUF_SIZE];↵

16

                FileInputStream fis1 = new FileInputStream(file1);↵

16

                FileInputStream fis1 = new FileInputStream(file1);↵

17

                FileInputStream fis2 = new FileInputStream(file2);↵

17

                FileInputStream fis2 = new FileInputStream(file2);↵

18

                int index = 0;↵

18

                int index = 0;↵

19

                int read = 0;↵

19

                int read = 0;↵

20

                while ((read = fis1.read(buffer1)) != -1) {↵

20

                while ((read = fis1.read(buffer1)) != -1) {↵

21

                    fis2.read(buffer2);↵

21

                    fis2.read(buffer2);↵

22

                    for (int i = 0; i < read; ++i, ++index) {↵

22

                    for (int i = 0; i < read; ++i, ++index) {↵

23

                        if (buffer1[i] != buffer2[i]) {↵

23

                        if (buffer1[i] != buffer2[i]) {↵

24

                            System.out.println("Bytes mismatch:" + name1 + ", " + name2 +↵

24

                            System.out.println("Bytes mismatch:" + name1 + ", " + name2 +↵

25

                                               " at byte " + index);↵

25

                                               " at byte " + index);↵

26

                            return false;↵

26

                            return false;↵

27

                        }↵

27

                        }↵

28

                    }↵

28

                    }↵

29

                }↵

29

                }↵

30

                return true;↵

30

                return true;↵

31

            }↵

31

            }↵

32

            catch (IOException e) {↵

32

            catch (IOException e) {↵

33

                System.out.println("IOException comparing files: " + name1 + ", " + name2);↵

33

                System.out.println("IOException comparing files: " + name1 + ", " + name2);↵

34

                return false;↵

34

                return false;↵

35

            }

35

            }

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 1
Number of non-refactorable cases | 0
Time elapsed for finding largest common nesting structure subtrees (ms) | 2.1
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 110

1. {Refactorable}

   Mapping Summary
   Number of mapped statements | 22
   Number of unmapped statements in the first code fragment | 0
   Number of unmapped statements in the second code fragment | 0
   Time elapsed for statement mapping (ms) | 6.6
   Clone type | Type 1

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       File file1 = new File(System.getProperty("root"), name1);

   1

       File file1 = new File(System.getProperty("root"), name1);

   2

       File file2 = new File(System.getProperty("root"), name2);

   2

       File file2 = new File(System.getProperty("root"), name2);

   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
   --- | ---