ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1795807 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/ components/core-streams/ components/core-streams/src/main/ja...
Date Mon, 22 May 2017 14:13:23 GMT
Author: veithen
Date: Mon May 22 14:13:23 2017
New Revision: 1795807

URL: http://svn.apache.org/viewvc?rev=1795807&view=rev
Log:
Optimize writing Base64 encoded data with the Serializer.

Added:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
  (with props)
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/CharacterDataReaderImpl.java
    webservices/axiom/trunk/components/core-streams/pom.xml
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ContentHandlerXmlHandler.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
Mon May 22 14:13:23 2017
@@ -19,7 +19,6 @@
 package org.apache.axiom.om.impl.intf;
 
 import java.io.IOException;
-import java.io.Writer;
 
 import javax.activation.DataHandler;
 
@@ -27,12 +26,13 @@ import org.apache.axiom.attachments.Byte
 import org.apache.axiom.core.ClonePolicy;
 import org.apache.axiom.core.CloneableCharacterData;
 import org.apache.axiom.core.stream.CharacterData;
+import org.apache.axiom.core.stream.CharacterDataSink;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.util.UIDGenerator;
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
 import org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream;
-import org.apache.axiom.util.base64.Base64EncodingWriterOutputStream;
 import org.apache.axiom.util.base64.Base64Utils;
 
 public final class TextContent implements CloneableCharacterData {
@@ -169,13 +169,14 @@ public final class TextContent implement
     }
 
     @Override
-    public void writeTo(Writer writer) throws IOException {
+    public void writeTo(CharacterDataSink sink) throws IOException {
         if (binary) {
-            Base64EncodingWriterOutputStream out = new Base64EncodingWriterOutputStream(writer,
4096, true);
+            AbstractBase64EncodingOutputStream out = sink.getBase64EncodingOutputStream();
             getDataHandler().writeTo(out);
             out.complete();
         } else {
-            writer.write(value);
+            // TODO: there must be a better way to just write a String
+            sink.getWriter().write(value);
         }
     }
 

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/CharacterDataReaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/CharacterDataReaderImpl.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/CharacterDataReaderImpl.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/pull/CharacterDataReaderImpl.java
Mon May 22 14:13:23 2017
@@ -25,8 +25,11 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.core.stream.CharacterData;
+import org.apache.axiom.core.stream.CharacterDataSink;
 import org.apache.axiom.core.stream.stax.pull.InternalXMLStreamReader;
 import org.apache.axiom.ext.stax.CharacterDataReader;
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+import org.apache.axiom.util.base64.Base64EncodingWriterOutputStream;
 
 final class CharacterDataReaderImpl implements CharacterDataReader {
     private final InternalXMLStreamReader reader;
@@ -36,12 +39,22 @@ final class CharacterDataReaderImpl impl
     }
 
     @Override
-    public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
+    public void writeTextTo(final Writer writer) throws XMLStreamException, IOException {
         switch (reader.getEventType()) {
             case XMLStreamReader.CHARACTERS:
                 Object data = reader.getCharacterData();
                 if (data instanceof CharacterData) {
-                    ((CharacterData)data).writeTo(writer);
+                    ((CharacterData)data).writeTo(new CharacterDataSink() {
+                        @Override
+                        public Writer getWriter() {
+                            return writer;
+                        }
+
+                        @Override
+                        public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream()
{
+                            return new Base64EncodingWriterOutputStream(writer);
+                        }
+                    });
                 } else {
                     writer.write(data.toString());
                 }

Modified: webservices/axiom/trunk/components/core-streams/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/pom.xml?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/pom.xml (original)
+++ webservices/axiom/trunk/components/core-streams/pom.xml Mon May 22 14:13:23 2017
@@ -41,6 +41,11 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>base64-utils</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
Mon May 22 14:13:23 2017
@@ -19,7 +19,6 @@
 package org.apache.axiom.core.stream;
 
 import java.io.IOException;
-import java.io.Writer;
 
 // TODO: clean up this Javadoc
 /**
@@ -29,6 +28,6 @@ import java.io.Writer;
  */
 public interface CharacterData {
     String toString();
-    void writeTo(Writer writer) throws IOException;
+    void writeTo(CharacterDataSink sink) throws IOException;
     void appendTo(StringBuilder buffer);
 }

Added: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java?rev=1795807&view=auto
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
(added)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
Mon May 22 14:13:23 2017
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.core.stream;
+
+import java.io.Writer;
+
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+
+public interface CharacterDataSink {
+    Writer getWriter();
+    AbstractBase64EncodingOutputStream getBase64EncodingOutputStream();
+}

Propchange: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ContentHandlerXmlHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ContentHandlerXmlHandler.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ContentHandlerXmlHandler.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ContentHandlerXmlHandler.java
Mon May 22 14:13:23 2017
@@ -19,18 +19,22 @@
 package org.apache.axiom.core.stream.sax;
 
 import java.io.IOException;
+import java.io.Writer;
 import java.util.Stack;
 
 import org.apache.axiom.core.stream.CharacterData;
+import org.apache.axiom.core.stream.CharacterDataSink;
 import org.apache.axiom.core.stream.StreamException;
 import org.apache.axiom.core.stream.XmlHandler;
 import org.apache.axiom.core.stream.util.CharacterDataAccumulator;
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+import org.apache.axiom.util.base64.Base64EncodingWriterOutputStream;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.AttributesImpl;
 
-public class ContentHandlerXmlHandler implements XmlHandler {
+public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
     private enum CharacterDataMode { PASS_THROUGH, BUFFER, SKIP, ACCUMULATE };
     
     private final ContentHandler contentHandler;
@@ -176,6 +180,16 @@ public class ContentHandlerXmlHandler im
         bufferPos += dataLen;
     }
 
+    @Override
+    public Writer getWriter() {
+        return new ContentHandlerWriter(contentHandler);
+    }
+
+    @Override
+    public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream() {
+        return new Base64EncodingWriterOutputStream(getWriter());
+    }
+
     public void processCharacterData(Object data, boolean ignorable) throws StreamException
{
         try {
             switch (characterDataMode) {
@@ -186,7 +200,7 @@ public class ContentHandlerXmlHandler im
                         bufferPos = 0;
                     } else if (data instanceof CharacterData) {
                         try {
-                            ((CharacterData)data).writeTo(new ContentHandlerWriter(contentHandler));
+                            ((CharacterData)data).writeTo(this);
                         } catch (IOException ex) {
                             Throwable cause = ex.getCause();
                             SAXException saxException;

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
Mon May 22 14:13:23 2017
@@ -25,11 +25,13 @@ import java.io.OutputStream;
 import java.io.Writer;
 
 import org.apache.axiom.core.stream.CharacterData;
+import org.apache.axiom.core.stream.CharacterDataSink;
 import org.apache.axiom.core.stream.StreamException;
 import org.apache.axiom.core.stream.XmlHandler;
 import org.apache.axiom.core.stream.serializer.writer.UnmappableCharacterHandler;
 import org.apache.axiom.core.stream.serializer.writer.WriterXmlWriter;
 import org.apache.axiom.core.stream.serializer.writer.XmlWriter;
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
 
 /**
  * This abstract class is a base class for other stream 
@@ -37,7 +39,7 @@ import org.apache.axiom.core.stream.seri
  * 
  * @xsl.usage internal
  */
-public final class Serializer implements XmlHandler {
+public final class Serializer implements XmlHandler, CharacterDataSink {
     /**
      * The number of characters to process at once. Chosen small enough to leverage processor
caches
      * and large enough to reduce method invocation overhead.
@@ -493,11 +495,21 @@ public final class Serializer implements
     }
 
     @Override
+    public Writer getWriter() {
+        return new SerializerWriter(this);
+    }
+
+    @Override
+    public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream() {
+        return writer.getBase64EncodingOutputStream();
+    }
+
+    @Override
     public void processCharacterData(Object data, boolean ignorable) throws StreamException
{
         closeStartTag();
         if (data instanceof CharacterData) {
             try {
-                ((CharacterData)data).writeTo(new SerializerWriter(this));
+                ((CharacterData)data).writeTo(this);
             } catch (IOException ex) {
                 Throwable cause = ex.getCause();
                 if (cause instanceof StreamException) {

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
Mon May 22 14:13:23 2017
@@ -21,10 +21,12 @@ package org.apache.axiom.core.stream.ser
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+
 abstract class ASCIICompatibleXmlWriter extends XmlWriter {
     private final OutputStream out;
-    private final byte[] buffer = new byte[4096];
-    private int bufferPosition;
+    final byte[] buffer = new byte[4096];
+    int bufferPosition;
     private char highSurrogate;
     
     ASCIICompatibleXmlWriter(OutputStream out) {
@@ -122,6 +124,32 @@ abstract class ASCIICompatibleXmlWriter
     }
 
     @Override
+    public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream() {
+        return new AbstractBase64EncodingOutputStream() {
+            @Override
+            protected void doWrite(byte[] b) throws IOException {
+                if (buffer.length-bufferPosition < 4) {
+                    ASCIICompatibleXmlWriter.this.flushBuffer();
+                }
+                System.arraycopy(b, 0, buffer, bufferPosition, 4);
+                bufferPosition += 4;
+            }
+            
+            @Override
+            protected void flushBuffer() throws IOException {
+            }
+            
+            @Override
+            protected void doFlush() throws IOException {
+            }
+            
+            @Override
+            protected void doClose() throws IOException {
+            }
+        };
+    }
+
+    @Override
     public final void flushBuffer() throws IOException {
         out.write(buffer, 0, bufferPosition);
         bufferPosition = 0;

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
Mon May 22 14:13:23 2017
@@ -26,6 +26,8 @@ import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CoderResult;
 
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+
 final class OutputStreamXmlWriter extends XmlWriter {
     private final OutputStream out;
     private final CharBuffer encoderIn;
@@ -140,6 +142,34 @@ final class OutputStreamXmlWriter extend
     }
 
     @Override
+    public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream() {
+        return new AbstractBase64EncodingOutputStream() {
+            @Override
+            protected void doWrite(byte[] b) throws IOException {
+                CharBuffer encoderIn = getEncoderIn();
+                if (encoderIn.remaining() < 4) {
+                    OutputStreamXmlWriter.this.flush(encoderIn);
+                }
+                for (int i=0; i<4; i++) {
+                    encoderIn.put((char)(b[i] & 0xFF));
+                }
+            }
+            
+            @Override
+            protected void flushBuffer() throws IOException {
+            }
+            
+            @Override
+            protected void doFlush() throws IOException {
+            }
+            
+            @Override
+            protected void doClose() throws IOException {
+            }
+        };
+    }
+
+    @Override
     public void flushBuffer() throws IOException {
         flush(encoderIn);
         flushEncodingOut();

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
Mon May 22 14:13:23 2017
@@ -21,6 +21,9 @@ package org.apache.axiom.core.stream.ser
 import java.io.IOException;
 import java.io.Writer;
 
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+import org.apache.axiom.util.base64.Base64EncodingWriterOutputStream;
+
 public final class WriterXmlWriter extends XmlWriter {
     private final Writer out;
 
@@ -48,6 +51,11 @@ public final class WriterXmlWriter exten
     }
 
     @Override
+    public AbstractBase64EncodingOutputStream getBase64EncodingOutputStream() {
+        return new Base64EncodingWriterOutputStream(out);
+    }
+
+    @Override
     public void flushBuffer() throws IOException {
     }
 }

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java?rev=1795807&r1=1795806&r2=1795807&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
Mon May 22 14:13:23 2017
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.charset.Charset;
 
+import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
+
 public abstract class XmlWriter {
     public static XmlWriter create(OutputStream out, String encoding) {
         Charset charset = Charset.forName(encoding);
@@ -42,6 +44,8 @@ public abstract class XmlWriter {
     public abstract void write(String s) throws IOException;
     public abstract void write(char chars[], int start, int length) throws IOException;
 
+    public abstract AbstractBase64EncodingOutputStream getBase64EncodingOutputStream();
+
     /**
      * Write any pending data to the underlying stream, without flushing the stream itself.
      * 



Mime
View raw message