Author: jleroux
Date: Mon Jun 9 04:30:50 2008
New Revision: 664682
URL:
http://svn.apache.org/viewvc?rev=664682&view=revLog:
A patch from Michael Brohl "FileUtil: write a file from a string with a specified encoding" (
https://issues.apache.org/jira/browse/OFBIZ-1829) - OFBIZ-1829
Modified:
ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java
Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java?rev=664682&r1=664681&r2=664682&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/FileUtil.java Mon Jun 9 04:30:50 2008
@@ -33,6 +33,8 @@
import java.util.List;
import java.util.Set;
+import org.apache.commons.io.FileUtils;
+
import javolution.util.FastList;
import javolution.util.FastSet;
@@ -66,6 +68,29 @@
}
}
}
+
+ /**
+ * Writes a file from a string with a specified encoding.
+ *
+ * @param path
+ * @param name
+ * @param encoding
+ * @param s
+ * @throws IOException
+ */
+ public static void writeString(String path, String name, String encoding, String s) throws IOException {
+ String fileName = getPatchedFileName(path, name);
+ if (UtilValidate.isEmpty(fileName)) {
+ throw new IOException("Cannot obtain buffered writer for an empty filename!");
+ }
+
+ try {
+ FileUtils.writeStringToFile(new File(fileName), s, encoding);
+ } catch (IOException e) {
+ Debug.logError(e, module);
+ throw e;
+ }
+ }
public static Writer getBufferedWriter(String path, String name) throws IOException {
String fileName = getPatchedFileName(path, name);