Update of 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload
In directory 
james.mmbase.org:/tmp/cvs-serv5809/staticdownload/src/java/com/finalist/cmsc/staticdownload

Modified Files:
        DownloadThread.java 
Log Message:
CMSC-1017 - Static download module uses inefficient functions to write files 
and doesn't close all file handles.


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload
See also: http://www.mmbase.org/jira/browse/CMSC-1017


Index: DownloadThread.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/staticdownload/src/java/com/finalist/cmsc/staticdownload/DownloadThread.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- DownloadThread.java 7 Jul 2008 20:52:35 -0000       1.7
+++ DownloadThread.java 15 Jul 2008 10:24:55 -0000      1.8
@@ -7,7 +7,6 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FileReader;
-import java.io.FileWriter;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -101,8 +100,7 @@
                        File file = new 
File(downloadSettings.getTempPath());//get the files which wget last download
                        setupSuffix();
                        modifyDownloadPath();
-                       findAssociatedFiles(file, new MyFilenameFilter(".css", 
".js",
-                                       ".html"));
+                       findAssociatedFiles(file, new MyFilenameFilter(".css", 
".js", ".html"));
                        redownload(redownloadfiles);
                        redownloadfiles.clear();//this will avoid to redownload 
picture in different request
                        zip();
@@ -188,15 +186,15 @@
 
                String outputData = fixFlash(inputData);
 
-               if (!outputData.equals(inputData)) {
+               if (inputData == null || !outputData.equals(inputData)) {
                        writeFile(file, outputData);
                }
        }
 
        private void writeFile(File file, String outputData) throws IOException 
{
-               FileWriter writer = null;
+          PrintWriter writer = null;
                try {
-                       writer = new FileWriter(file);
+                       writer = new PrintWriter(file);
                        writer.write(outputData);
                        writer.flush();
                } finally {
@@ -208,20 +206,23 @@
 
        private String readFile(File file) throws IOException {
                BufferedReader reader = null;
+               StringBuffer buffer = null;
                try {
                        reader = new BufferedReader(new FileReader(file));
-
-                       StringBuffer buffer = new StringBuffer();
+                       buffer = new StringBuffer();
                        String line;
                        while ((line = reader.readLine()) != null) {
                                buffer.append(line);
                        }
-                       return buffer.toString();
                } finally {
                        if (reader != null) {
                                reader.close();
                        }
                }
+      if (buffer != null) {
+         return buffer.toString();
+      } else return null;
+      
        }
 
        private boolean includeFile(String name) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to