Author: doogie
Date: Mon Mar 15 04:36:22 2010
New Revision: 923052
URL:
http://svn.apache.org/viewvc?rev=923052&view=revLog:
Add new helper method to make constructing simpler.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/IndentingWriter.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/IndentingWriterTests.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/IndentingWriter.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/IndentingWriter.java?rev=923052&r1=923051&r2=923052&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/IndentingWriter.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/IndentingWriter.java Mon Mar 15 04:36:22 2010
@@ -28,6 +28,10 @@ public class IndentingWriter extends Fil
protected final boolean doNewline;
protected boolean lastWasNewline;
+ public static IndentingWriter makeIndentingWriter(Writer writer) {
+ return writer instanceof IndentingWriter ? (IndentingWriter) writer : new IndentingWriter(writer);
+ }
+
public IndentingWriter(Writer out, boolean doSpace, boolean doNewline) {
super(out);
this.doSpace = doSpace;
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/IndentingWriterTests.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/IndentingWriterTests.java?rev=923052&r1=923051&r2=923052&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/IndentingWriterTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/IndentingWriterTests.java Mon Mar 15 04:36:22 2010
@@ -58,6 +58,9 @@ public class IndentingWriterTests extend
}
public void testIndentingWriter() throws Exception {
+ StringWriter sw = new StringWriter();
+ IndentingWriter iw = IndentingWriter.makeIndentingWriter(sw);
+ assertSame("makeIndentingWriter - pass-thru", iw, IndentingWriter.makeIndentingWriter(iw));
doTest("IndentingWriter doSpace:doNewline", true, true, "ab\n m\n 1\n 2 \n e");
doTest("IndentingWriter doNewline", false, true, "ab\nm\n1\n2\ne");
doTest("IndentingWriter doSpace", true, false, "ab\n m 1\n 2 \n e");