Author: dims
Date: Fri Feb 23 09:15:04 2007
New Revision: 511021

URL: http://svn.apache.org/viewvc?view=rev&rev=511021
Log:
Fix for WSCOMMONS-142 - Inefficient code in TextImpl and OMTextImpl. Took the 
opportunity to remove duplicate code

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/TextHelper.java
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/TextHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/TextHelper.java?view=auto&rev=511021
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/TextHelper.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/TextHelper.java
 Fri Feb 23 09:15:04 2007
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.om.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class TextHelper {
+    public static String toString(InputStream inStream) throws IOException {
+        byte[] data;
+        StringBuffer text = new StringBuffer();
+        do {
+            data = new byte[1023];
+            int len;
+            while ((len = inStream.read(data)) > 0) {
+                text.append(Base64.encode(data, 0, len));
+            }
+        } while (inStream.available() > 0);
+        return text.toString();
+    }
+}

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java?view=diff&rev=511021&r1=511020&r2=511021
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
 Fri Feb 23 09:15:04 2007
@@ -22,6 +22,7 @@
 import org.apache.axiom.om.impl.builder.XOPBuilder;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.om.util.TextHelper;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
 import org.w3c.dom.Text;
@@ -312,22 +313,7 @@
             return getTextFromProperPlace();
         } else {
             try {
-                InputStream inStream;
-                inStream = this.getInputStream();
-                // int x = inStream.available();
-                byte[] data;
-                StringBuffer text = new StringBuffer();
-                do {
-                    data = new byte[1024];
-                    int len;
-                    while ((len = inStream.read(data)) > 0) {
-                        byte[] temp = new byte[len];
-                        System.arraycopy(data, 0, temp, 0, len);
-                        text.append(Base64.encode(temp));
-                    }
-
-                } while (inStream.available() > 0);
-                return text.toString();
+                return TextHelper.toString(getInputStream());
             } catch (Exception e) {
                 throw new OMException(e);
             }
@@ -373,22 +359,7 @@
             return new QName(getTextFromProperPlace());
         } else {
             try {
-                InputStream inStream;
-                inStream = this.getInputStream();
-                byte[] data;
-                StringBuffer text = new StringBuffer();
-                do {
-                    data = new byte[1024];
-                    int len;
-                    while ((len = inStream.read(data)) > 0) {
-                        byte[] temp = new byte[len];
-                        System.arraycopy(data, 0, temp, 0, len);
-                        text.append(Base64.encode(temp));
-                    }
-
-                } while (inStream.available() > 0);
-
-                return new QName(text.toString());
+                return new QName(TextHelper.toString(getInputStream()));
             } catch (Exception e) {
                 throw new OMException(e);
             }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?view=diff&rev=511021&r1=511020&r2=511021
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
 Fri Feb 23 09:15:04 2007
@@ -24,6 +24,7 @@
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.om.util.TextHelper;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -227,23 +228,7 @@
             return getTextFromProperPlace();
         } else {
             try {
-                               // TODO we have the following code duplicated 
in getTextAsQName
-                               InputStream inStream;
-                inStream = this.getInputStream();
-                byte[] data;
-                StringBuffer text = new StringBuffer();
-                do {
-                    data = new byte[1023];
-                    int len;
-                    while ((len = inStream.read(data)) > 0) {
-                        byte[] temp = new byte[len];
-                        System.arraycopy(data, 0, temp, 0, len);
-                        text.append(Base64.encode(temp));
-                    }
-
-                } while (inStream.available() > 0);
-
-                return text.toString();
+                return TextHelper.toString(getInputStream());
             } catch (Exception e) {
                 throw new OMException(e);
             }
@@ -284,22 +269,7 @@
             return new QName(getTextFromProperPlace());
         } else {
             try {
-                InputStream inStream;
-                inStream = this.getInputStream();
-                byte[] data;
-                StringBuffer text = new StringBuffer();
-                do {
-                    data = new byte[1023];
-                    int len;
-                    while ((len = inStream.read(data)) > 0) {
-                        byte[] temp = new byte[len];
-                        System.arraycopy(data, 0, temp, 0, len);
-                        text.append(Base64.encode(temp));
-                    }
-
-                } while (inStream.available() > 0);
-
-                return new QName(text.toString());
+                return new QName(TextHelper.toString(getInputStream()));
             } catch (Exception e) {
                 throw new OMException(e);
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to