ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1332637 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64: Base64EncodingStringBufferOutputStream.java Base64Utils.java
Date Tue, 01 May 2012 13:11:25 GMT
Author: veithen
Date: Tue May  1 13:11:25 2012
New Revision: 1332637

URL: http://svn.apache.org/viewvc?rev=1332637&view=rev
Log:
Prefer StringBuilder over StringBuffer.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingStringBufferOutputStream.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64Utils.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingStringBufferOutputStream.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingStringBufferOutputStream.java?rev=1332637&r1=1332636&r2=1332637&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingStringBufferOutputStream.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingStringBufferOutputStream.java
Tue May  1 13:11:25 2012
@@ -23,10 +23,11 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 /**
- * {@link OutputStream} implementation that writes base64 encoded data to a {@link StringBuffer}.
+ * {@link OutputStream} implementation that writes base64 encoded data to a {@link StringBuffer}
or
+ * {@link StringBuilder}. The data is <b>not</b> buffered before writing it to
the target.
  */
 public class Base64EncodingStringBufferOutputStream extends AbstractBase64EncodingOutputStream
{
-    private final StringBuffer buffer;
+    private final Appendable buffer;
 
     /**
      * Constructor.
@@ -37,6 +38,15 @@ public class Base64EncodingStringBufferO
         this.buffer = buffer;
     }
 
+    /**
+     * Constructor.
+     * 
+     * @param buffer the buffer to append the encoded data to
+     */
+    public Base64EncodingStringBufferOutputStream(StringBuilder buffer) {
+        this.buffer = buffer;
+    }
+
     protected void doWrite(byte[] b) throws IOException {
         for (int i=0; i<4; i++) {
             buffer.append((char)(b[i] & 0xFF));

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64Utils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64Utils.java?rev=1332637&r1=1332636&r2=1332637&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64Utils.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64Utils.java
Tue May  1 13:11:25 2012
@@ -64,14 +64,14 @@ public class Base64Utils {
      */
     public static String encode(DataHandler dh) throws IOException {
         long size = DataSourceUtils.getSize(dh.getDataSource());
-        StringBuffer buffer;
+        StringBuilder buffer;
         if (size == -1) {
             // Use a reasonable default capacity (better than the default of 16).
-            buffer = new StringBuffer(4096);
+            buffer = new StringBuilder(4096);
         } else if (size > Integer.MAX_VALUE) {
             throw new IllegalArgumentException("DataHandler is too large to encode to string");
         } else {
-            buffer = new StringBuffer(getEncodedSize((int)size));
+            buffer = new StringBuilder(getEncodedSize((int)size));
         }
         Base64EncodingStringBufferOutputStream out = new Base64EncodingStringBufferOutputStream(buffer);
         // Always prefer writeTo, because getInputStream will create a thread and a pipe
if



Mime
View raw message