abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1056044 - in /abdera/java/trunk/extensions/json/src: main/java/org/apache/abdera/ext/json/JSONStream.java main/java/org/apache/abdera/ext/json/JSONUtil.java test/java/org/apache/abdera/ext/json/JSONStreamTest.java
Date Thu, 06 Jan 2011 19:53:08 GMT
Author: antelder
Date: Thu Jan  6 19:53:07 2011
New Revision: 1056044

URL: http://svn.apache.org/viewvc?rev=1056044&view=rev
Log:
ABDERA-277: Apply patch from Olve Sæther Hansen to fix Excessive calls to flush() on the
Writer responsible for writing JSONStream data.

Modified:
    abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.java
    abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.java
    abdera/java/trunk/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.java

Modified: abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.java?rev=1056044&r1=1056043&r2=1056044&view=diff
==============================================================================
--- abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.java
(original)
+++ abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.java
Thu Jan  6 19:53:07 2011
@@ -66,19 +66,16 @@ public class JSONStream {
         for (int n = 0; n < depth; n++) {
             writer.write(' ');
         }
-        writer.flush();
     }
 
     private void writeNewLine() throws IOException {
         writer.write('\n');
-        writer.flush();
     }
 
     public void startObject() throws IOException {
         writer.write('{');
         inc();
         pushStack();
-        writer.flush();
     }
 
     public void endObject() throws IOException {
@@ -87,13 +84,11 @@ public class JSONStream {
         writeNewLine();
         writeIndent();
         writer.write('}');
-        writer.flush();
     }
 
     public void startArray() throws IOException {
         writer.write('[');
         inc();
-        writer.flush();
     }
 
     public void endArray() throws IOException {
@@ -101,17 +96,14 @@ public class JSONStream {
         writeNewLine();
         writeIndent();
         writer.write(']');
-        writer.flush();
     }
 
     public void writeSeparator() throws IOException {
         writer.write(',');
-        writer.flush();
     }
 
     private void writeColon() throws IOException {
         writer.write(':');
-        writer.flush();
     }
 
     public void writeQuoted(String value) throws IOException {
@@ -119,7 +111,6 @@ public class JSONStream {
             writer.write('"');
             writer.write(escape(value));
             writer.write('"');
-            writer.flush();
         }
     }
 
@@ -169,7 +160,6 @@ public class JSONStream {
             writeField(name);
             writer.write(value.toString());
         }
-        writer.flush();
     }
 
     public void writeField(String name, Boolean value) throws IOException {
@@ -177,7 +167,6 @@ public class JSONStream {
             writeField(name);
             writer.write(value.toString());
         }
-        writer.flush();
     }
 
     private static String escape(String value) {

Modified: abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.java?rev=1056044&r1=1056043&r2=1056044&view=diff
==============================================================================
--- abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.java
(original)
+++ abdera/java/trunk/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.java
Thu Jan  6 19:53:07 2011
@@ -63,7 +63,6 @@ public class JSONUtil {
         } else if (base instanceof Element) {
             toJson((Element)base, jstream);
         }
-        writer.flush();
     }
 
     private static boolean isSameAsParentBase(Element element) {

Modified: abdera/java/trunk/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.java?rev=1056044&r1=1056043&r2=1056044&view=diff
==============================================================================
--- abdera/java/trunk/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.java
(original)
+++ abdera/java/trunk/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.java
Thu Jan  6 19:53:07 2011
@@ -18,12 +18,14 @@
 package org.apache.abdera.ext.json;
 
 import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayOutputStream;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.writer.Writer;
+import org.apache.abdera.writer.WriterOptions;
 import org.junit.Test;
 
 public class JSONStreamTest {
@@ -37,7 +39,9 @@ public class JSONStreamTest {
 
         Writer json = abdera.getWriterFactory().getWriter("json");
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        entry.writeTo(json, outputStream);
+        WriterOptions opts = entry.getDefaultWriterOptions();
+        opts.setAutoClose(true);
+        entry.writeTo(json, outputStream, opts);
         String output = outputStream.toString();
         assertTrue(output.contains("\"type\":\"text/xml\""));
         assertTrue(output.contains("\"src\":\"http://example.org/xml\""));



Mime
View raw message