简体   繁体   中英

How do I compare two ods documents programmatically in Java?

I'm generating an ODS spreadsheet as an output from a Java program. I am currently trying to set up test cases for the same. In order to this, I need to compare the expected and actual outputs. I am currently using ODFToolkit to create the document.

How do I compare the two spreadsheets (expected and actual) in a Java program?

In case anyone needs the solution, here it is

public static boolean contentsAreIdentical(OdfSpreadsheetDocument document1, OdfSpreadsheetDocument document2) {  
    try {  
        ByteArrayInputStream bis1 = (ByteArrayInputStream) document1.getContentStream();  
        ByteArrayInputStream bis2 = (ByteArrayInputStream) document2.getContentStream();  

        if(bis1.available() != bis2.available()) {  
            return false;  
        }  

        while(true){  
            int a = bis1.read();  
                            int b = bis2.read();  
                            if(a != b){  
                                    return false;  
                            }  
                            if(a == -1){  
                                    return true;  
                            }  
                  }  
    } catch (Exception e) {  
        //Do something with exception  
    }  
    return false;  
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM