You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/05/09 18:58:03 UTC

svn commit: r1743026 - /webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/

Author: veithen
Date: Mon May  9 18:58:02 2016
New Revision: 1743026

URL: http://svn.apache.org/viewvc?rev=1743026&view=rev
Log:
Avoid unnecessarily flushing the underlying stream in the serializer.

Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/SerializerBase.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToStream.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToXMLStream.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToASCI.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToUTF8Buffered.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterXmlWriter.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/XmlWriter.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/SerializerBase.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/SerializerBase.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/SerializerBase.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/SerializerBase.java Mon May  9 18:58:02 2016
@@ -20,7 +20,6 @@
  */
 package org.apache.axiom.core.stream.serializer;
 
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.Set;
 
@@ -584,30 +583,6 @@ public abstract class SerializerBase
 //        
 
     /**
-     * This method is only used internally when flushing the writer from the
-     * various fire...() trace events.  Due to the writer being wrapped with 
-     * SerializerTraceWriter it may cause the flush of these trace events:
-     * EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS 
-     * EVENTTYPE_OUTPUT_CHARACTERS
-     * which trace the output written to the output stream.
-     * 
-     */
-    private void flushMyWriter()
-    {
-        if (m_writer != null)
-        {
-            try
-            {
-                m_writer.flush();
-            }
-            catch(IOException ioe)
-            {
-            
-            }
-        }
-    }
-
-    /**
      * Receive notification of the beginning of a document.
      * This method is never a self generated call, 
      * but only called externally.

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToStream.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToStream.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToStream.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToStream.java Mon May  9 18:58:02 2016
@@ -128,9 +128,6 @@ abstract public class ToStream extends S
      */
     protected CharInfo m_charInfo;
 
-    /** True if we control the buffer, and we should flush the output on endDocument. */
-    boolean m_shouldFlush = true;
-
     /**
      * Add space before '/>' for XHTML.
      */
@@ -198,45 +195,6 @@ abstract public class ToStream extends S
      */
     protected boolean m_escaping = true;
 
-    /**
-     * Flush the formatter's result stream.
-     *
-     * @throws StreamException
-     */
-    protected final void flushWriter() throws StreamException
-    {
-        final XmlWriter writer = m_writer;
-        if (null != writer)
-        {
-            try
-            {
-                if (writer instanceof WriterToUTF8Buffered)
-                {
-                    if (m_shouldFlush)
-                         ((WriterToUTF8Buffered) writer).flush();
-                    else
-                         ((WriterToUTF8Buffered) writer).flushBuffer();
-                }
-                if (writer instanceof WriterToASCI)
-                {
-                    if (m_shouldFlush)
-                        writer.flush();
-                }
-                else
-                {
-                    // Flush always. 
-                    // Not a great thing if the writer was created 
-                    // by this class, but don't have a choice.
-                    writer.flush();
-                }
-            }
-            catch (IOException ioe)
-            {
-                throw new StreamException(ioe);
-            }
-        }
-    }
-
     OutputStream m_outputStream;
     /**
      * Get the output stream where the events will be serialized to.
@@ -498,9 +456,6 @@ abstract public class ToStream extends S
      */
     public void setOutputFormat(Properties format)
     {
-
-        boolean shouldFlush = m_shouldFlush;
-        
         if (format != null)
         {
             // Set the default values first,
@@ -537,11 +492,6 @@ abstract public class ToStream extends S
 
             m_charInfo = CharInfo.getCharInfo(entitiesFileName);
         }
-
-
-         
-
-        m_shouldFlush = shouldFlush;
     }
 
     /**
@@ -584,7 +534,7 @@ abstract public class ToStream extends S
      */
     public void setWriter(Writer writer)
     {        
-        setWriterInternal(new WriterXmlWriter(writer), true);
+        setWriterInternal(new WriterXmlWriter(writer, false), true);
     }
     
     protected boolean m_writer_set_by_user;
@@ -674,12 +624,12 @@ abstract public class ToStream extends S
                     e.printStackTrace();
                 }
             }
-            setWriterInternal(new WriterXmlWriter(osw), false);
+            setWriterInternal(new WriterXmlWriter(osw, true), false);
         }
         else {
             // don't have any encoding, but we have an OutputStream
             Writer osw = new OutputStreamWriter(output);
-            setWriterInternal(new WriterXmlWriter(osw), false);
+            setWriterInternal(new WriterXmlWriter(osw, true), false);
         }
     }
 
@@ -2334,7 +2284,7 @@ abstract public class ToStream extends S
             }
             if (m_writer != null) {
                 try {
-                    m_writer.flush();
+                    m_writer.flushBuffer();
                 }
                 catch(IOException e) {
                     // what? me worry?
@@ -2390,7 +2340,6 @@ abstract public class ToStream extends S
          this.m_lineSepUse = true;
          // this.m_outputStream = null; // Don't reset it may be re-used
          this.m_preserves.clear();
-         this.m_shouldFlush = true;
          this.m_spaceBeforeClose = false;
          this.m_startNewLine = false;
          this.m_writer_set_by_user = false;

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToXMLStream.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToXMLStream.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToXMLStream.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/ToXMLStream.java Mon May  9 18:58:02 2016
@@ -185,7 +185,11 @@ public class ToXMLStream extends ToStrea
             }
         }
 
-        flushWriter();
+        try {
+            m_writer.flushBuffer();
+        } catch (IOException ex) {
+            throw new StreamException(ex);
+        }
     }
 
     /**

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToASCI.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToASCI.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToASCI.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToASCI.java Mon May  9 18:58:02 2016
@@ -107,17 +107,6 @@ final class WriterToASCI extends XmlWrit
     }
   }
 
-  /**
-   * Flush the stream.  If the stream has saved any characters from the
-   * various write() methods in a buffer, write them immediately to their
-   * intended destination.  Then, if that destination is another character or
-   * byte stream, flush it.  Thus one flush() invocation will flush all the
-   * buffers in a chain of Writers and OutputStreams.
-   *
-   * @exception  IOException  If an I/O error occurs
-   */
-  void flush() throws java.io.IOException
-  {
-    m_os.flush();
+  void flushBuffer() {
   }
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToUTF8Buffered.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToUTF8Buffered.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToUTF8Buffered.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterToUTF8Buffered.java Mon May  9 18:58:02 2016
@@ -433,11 +433,6 @@ final class WriterToUTF8Buffered extends
 
   }
 
-  /**
-   * Flush the internal buffer
-   *
-   * @throws IOException
-   */
   void flushBuffer() throws IOException
   {
 
@@ -448,21 +443,4 @@ final class WriterToUTF8Buffered extends
       count = 0;
     }
   }
-
-  /**
-   * Flush the stream.  If the stream has saved any characters from the
-   * various write() methods in a buffer, write them immediately to their
-   * intended destination.  Then, if that destination is another character or
-   * byte stream, flush it.  Thus one flush() invocation will flush all the
-   * buffers in a chain of Writers and OutputStreams.
-   *
-   * @exception  IOException  If an I/O error occurs
-   *
-   * @throws java.io.IOException
-   */
-  void flush() throws java.io.IOException
-  {
-    flushBuffer();
-    m_os.flush();
-  }
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterXmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterXmlWriter.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterXmlWriter.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/WriterXmlWriter.java Mon May  9 18:58:02 2016
@@ -23,9 +23,11 @@ import java.io.Writer;
 
 final class WriterXmlWriter extends XmlWriter {
     private final Writer out;
+    private final boolean flushWriter;
 
-    WriterXmlWriter(Writer out) {
+    WriterXmlWriter(Writer out, boolean flushWriter) {
         this.out = out;
+        this.flushWriter = flushWriter;
     }
 
     @Override
@@ -44,7 +46,9 @@ final class WriterXmlWriter extends XmlW
     }
 
     @Override
-    void flush() throws IOException {
-        out.flush();
+    void flushBuffer() throws IOException {
+        if (flushWriter) {
+            out.flush();
+        }
     }
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/XmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/XmlWriter.java?rev=1743026&r1=1743025&r2=1743026&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/XmlWriter.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/serializer/XmlWriter.java Mon May  9 18:58:02 2016
@@ -24,7 +24,13 @@ abstract class XmlWriter {
     abstract void write(char c) throws IOException;
     abstract void write(String s) throws IOException;
     abstract void write(char chars[], int start, int length) throws IOException;
-    abstract void flush() throws IOException;
+
+    /**
+     * Write any pending data to the underlying stream, without flushing the stream itself.
+     * 
+     * @throws IOException
+     */
+    abstract void flushBuffer() throws IOException;
     
     final void writeCharacterReference(int codePoint) throws IOException {
         write("&#");