Error while unzipping saved reports

I am using openmrs-module-reporting to generate reports (all previous versions till

Once I generate report and restart the application, reports generated before restart shows error.

I did found issue in function : inFile, File outFile).

Same issue can resolved by replacing current readStringFromFile function with :

public static String readStringFromFile(File f) throws IOException {
    String ret = null;
    StringBuilder fileContents = new StringBuilder((int)f.length());
    Scanner scanner = new Scanner(f);
    String lineSeparator = System.getProperty("line.separator");
    try {
        while(scanner.hasNextLine()) {        
            fileContents.append(scanner.nextLine() + lineSeparator);
        ret = fileContents.toString();
    } finally {

Can any one suggest what should be done? Otherwise we have to replace replicate the module and make required changes.

Note - latest version of reporting module does not support Openmrs version we are using.

@sagarbele, sorry for the trouble. Can you share a little more detail to help us reproduce the problem?

The existing “readStringFromFile” method will first try to de-compress the file if it’s extension ends with “.gz”. Is it possible that your report has a “.gz” extension but isn’t actually compressed? If so it could be that the issue is in the writing of the report output correctly, rather than in the reading of the output file for viewing.

Can you share the saved report that is failing to open (you can find this in your REPORT_RESULTS folder) or can you share a failing unit test that demonstrates the problem?

Thanks, Mike

@mseaton, yes the report is having an extension of “.gz”, but as I could open it directly without decompressing it, it might not have got compressed, link to sample report generated for regenerating issue -

No need to reinvent the wheel

Note: this works only if the file is text (and your method too). For compressed ones (binary) it won’t work.

Actually it’s an uncompressed XML file without encoding (this could be a problem in some languages). If parsing is required there’s no need to store it in a String, XML parsers do just fine with input streams.

@sagarbele, this does seem to be a bug. From what I can gather, this is limited to where the report is rendered to the default “Web” renderer, rather than to any non-web renderer. If you were going to go into your REPORT_DATA folder and rename all of your *.reportdata.gz to *.reportdata, my guess is that things will work. We can raise a ticket for this and apply a fix for the next version of reporting. If you need this backported to a version that is compatible with you, then it may be that you need to fork and create a point release for yourself that contains the necessary fix.

I have created a ticket for this issue here:

@sagarbele, I’ve pushed a fix for this into the master branch here:

Thanks @mseaton.