package org.openhds.webservice;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

public class CacheResponseWriter {

    public static void writeResponse(File fileToWrite, HttpServletResponse response) throws IOException {
        if (!fileToWrite.exists()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }

        response.setStatus(HttpServletResponse.SC_OK);

        InputStream is = null;
        try {
            is = new BufferedInputStream(new FileInputStream(fileToWrite));
            IOUtils.copy(is, response.getOutputStream());
        } finally {
            if (is != null) {
                IOUtils.closeQuietly(is);
            }
        }
    }
}

@@ -514,16 +514,29 @@
       %7D%0A
+        else%7B
 %0A       
@@ -528,32 +528,33 @@
   else%7B%0A        
+%09
 response.setStat
@@ -585,16 +585,17 @@
 C_OK);%0A%0A
+%09
         
@@ -617,16 +617,17 @@
 = null;%0A
+%09
         
@@ -628,24 +628,25 @@
       try %7B%0A
+%09
             
@@ -705,24 +705,25 @@
 eToWrite));%0A
+%09
             
@@ -768,16 +768,17 @@
 eam());%0A
+%09
         
@@ -789,16 +789,17 @@
 nally %7B%0A
+%09
         
@@ -816,24 +816,25 @@
  != null) %7B%0A
+%09
             
@@ -863,20 +863,32 @@
 ly(is);%0A
-    
+%09            %7D%0A%09
         

Write Http-ErrorCode 404 if cached xml file for task does not exist