[OFBiz] SVN: r7040 - trunk/base/src/base/org/ofbiz/base/util

jaz@svn.ofbiz.org jaz at svn.ofbiz.org
Tue Mar 21 13:29:36 CST 2006


Author: jaz
Date: 2006-03-21 13:29:34 -0600 (Tue, 21 Mar 2006)
New Revision: 7040

Modified:
   trunk/base/src/base/org/ofbiz/base/util/FileUtil.java
Log:
moved into sevaral re-usable methods


Modified: trunk/base/src/base/org/ofbiz/base/util/FileUtil.java
===================================================================
--- trunk/base/src/base/org/ofbiz/base/util/FileUtil.java	2006-03-21 17:14:23 UTC (rev 7039)
+++ trunk/base/src/base/org/ofbiz/base/util/FileUtil.java	2006-03-21 19:29:34 UTC (rev 7040)
@@ -45,7 +45,35 @@
         writeString(null, fileName, s);
     }
 
-    public static void writeString(String path, String fileName, String s) throws IOException {
+    public static void writeString(String path, String name, String s) throws IOException {      
+        Writer out = getBufferedWriter(path, name);
+
+        try {
+            out.write(s + System.getProperty("line.separator"));
+        } catch (IOException e) {
+            Debug.logError(e, module);
+            throw e;
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    Debug.logError(e, module);
+                }
+            }
+        }
+    }
+
+    public static Writer getBufferedWriter(String path, String name) throws IOException {
+        String fileName = getPatchedFileName(path, name);
+        if (UtilValidate.isEmpty(fileName)) {
+            throw new IOException("Cannot obtain buffered writer for an empty filename!");
+        }
+
+        return new BufferedWriter(new FileWriter(fileName));
+    }
+
+    public static String getPatchedFileName(String path, String fileName) throws IOException {
         // make sure the export directory exists
         if (UtilValidate.isNotEmpty(path)) {
             path = path.replaceAll("\\\\", "/");
@@ -66,24 +94,6 @@
             fileName = path + fileName;
         }
 
-        if (UtilValidate.isNotEmpty(fileName)) {
-            // write the string
-            Writer out = null;
-            try {
-                out = new BufferedWriter(new FileWriter(fileName));
-                out.write(s + System.getProperty("line.separator"));
-            } catch (IOException e) {
-                Debug.logError(e, module);
-                throw e;
-            } finally {
-                if (out != null) {
-                    try {
-                        out.close();
-                    } catch (IOException e) {
-                        Debug.logError(e, module);
-                    }
-                }
-            }
-        }
+        return fileName;
     }
 }



More information about the Svn mailing list