svn commit: r1040799 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1040799 - /ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java

doogie-3
Author: doogie
Date: Tue Nov 30 22:03:46 2010
New Revision: 1040799

URL: http://svn.apache.org/viewvc?rev=1040799&view=rev
Log:
Make use of several copy() helper methods in UtilIO; these methods all use an internal buffer, instead of the old code that copied 1 byte or 1 character at a time.

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java?rev=1040799&r1=1040798&r2=1040799&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/data/DataResourceWorker.java Tue Nov 30 22:03:46 2010
@@ -56,6 +56,7 @@ import org.ofbiz.base.util.FileUtil;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilIO;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
@@ -895,11 +896,8 @@ public class DataResourceWorker  impleme
             if (!file.isAbsolute()) {
                 throw new GeneralException("File (" + objectInfo + ") is not absolute");
             }
-            int c;
             FileReader in = new FileReader(file);
-            while ((c = in.read()) != -1) {
-                out.append((char)c);
-            }
+            UtilIO.copy(in, true, out);
         } else if (dataResourceTypeId.equals("OFBIZ_FILE")) {
             String prefix = System.getProperty("ofbiz.home");
             String sep = "";
@@ -907,10 +905,8 @@ public class DataResourceWorker  impleme
                 sep = "/";
             }
             File file = FileUtil.getFile(prefix + sep + objectInfo);
-            int c;
             FileReader in = new FileReader(file);
-            while ((c = in.read()) != -1)
-                out.append((char)c);
+            UtilIO.copy(in, true, out);
         } else if (dataResourceTypeId.equals("CONTEXT_FILE")) {
             String prefix = rootDir;
             String sep = "";
@@ -918,7 +914,6 @@ public class DataResourceWorker  impleme
                 sep = "/";
             }
             File file = FileUtil.getFile(prefix + sep + objectInfo);
-            int c;
             FileReader in = null;
             try {
                 in = new FileReader(file);
@@ -931,9 +926,7 @@ public class DataResourceWorker  impleme
             } catch (Exception e) {
                 Debug.logError(" in renderDataResourceAsHtml(CONTEXT_FILE), got exception:" + e.getMessage(), module);
             }
-            while ((c = in.read()) != -1) {
-                out.append((char)c);
-            }
+            UtilIO.copy(in, true, out);
             //out.flush();
         }
     }
@@ -1112,19 +1105,13 @@ public class DataResourceWorker  impleme
                     url = new URL(s2);
                 }
                 InputStream in = url.openStream();
-                int c;
-                while ((c = in.read()) != -1) {
-                    os.write(c);
-                }
+                UtilIO.copy(in, true, os, false);
             } else if (dataResourceTypeId.indexOf("_FILE") >= 0) {
                 String objectInfo = dataResource.getString("objectInfo");
                 File inputFile = getContentFile(dataResourceTypeId, objectInfo, rootDir);
                 //long fileSize = inputFile.length();
                 FileInputStream fis = new FileInputStream(inputFile);
-                int c;
-                while ((c = fis.read()) != -1) {
-                    os.write(c);
-                }
+                UtilIO.copy(fis, true, os, false);
             } else {
                 throw new GeneralException("The dataResourceTypeId [" + dataResourceTypeId + "] is not supported in streamDataResource");
             }