hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r315053 - in /jakarta/httpclient/trunk/http-common/src: java/org/apache/http/ java/org/apache/http/entity/ java/org/apache/http/impl/ java/org/apache/http/impl/io/ java/org/apache/http/util/ test/org/apache/http/util/
Date Wed, 12 Oct 2005 21:32:48 GMT
Author: olegk
Date: Wed Oct 12 14:32:29 2005
New Revision: 315053

URL: http://svn.apache.org/viewcvs?rev=315053&view=rev
Log:
* Added non-synchronized CharArrayBuffer class
* Changed existing classes to use CharArrayBuffer instead of StringBuffer
* Added test cases for ByteArrayBuffer and CharArrayBuffer classes

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
  (with props)
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
  (with props)
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
  (with props)
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Header.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderElement.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpVersion.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NameValuePair.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestLine.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/HeaderGroup.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/ByteArrayBuffer.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Header.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Header.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Header.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/Header.java Wed Oct 12 14:32:29
2005
@@ -29,6 +29,7 @@
 
 package org.apache.http;
 
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.LangUtils;
 
 /**
@@ -115,7 +116,7 @@
      * @return a string
      */
     public String toString() {
-        StringBuffer buffer = new StringBuffer();
+        CharArrayBuffer buffer = new CharArrayBuffer(128);
         buffer.append(this.name);
         buffer.append(": ");
         buffer.append(this.value);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderElement.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderElement.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderElement.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HeaderElement.java Wed Oct
12 14:32:29 2005
@@ -32,6 +32,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.LangUtils;
 import org.apache.http.util.ParameterParser;
 
@@ -296,7 +297,7 @@
     }
     
     public String toString() {
-        StringBuffer buffer = new StringBuffer();
+        CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append(this.name);
         if (this.value != null) {
             buffer.append(" = ");

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java Wed Oct 12
14:32:29 2005
@@ -29,6 +29,7 @@
 
 package org.apache.http;
 
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.LangUtils;
 
 /**
@@ -147,23 +148,23 @@
      * @return The host uri.
      */
     public String toURI() {
-        StringBuffer buffer = new StringBuffer();        
+    	CharArrayBuffer buffer = new CharArrayBuffer(32);        
         buffer.append(this.protocol.getScheme());
         buffer.append("://");
         buffer.append(this.hostname);
         if (this.port != this.protocol.getDefaultPort()) {
             buffer.append(':');
-            buffer.append(this.port);
+            buffer.append(Integer.toString(this.port));
         }
         return buffer.toString();
     }
 
     public String toHostString() {
-        StringBuffer buffer = new StringBuffer();        
+    	CharArrayBuffer buffer = new CharArrayBuffer(32);        
         buffer.append(this.hostname);
         if (this.port != this.protocol.getDefaultPort()) {
             buffer.append(':');
-            buffer.append(this.port);
+            buffer.append(Integer.toString(this.port));
         }
         return buffer.toString();
     }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpVersion.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpVersion.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpVersion.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpVersion.java Wed Oct
12 14:32:29 2005
@@ -29,6 +29,8 @@
 
 package org.apache.http;
 
+import org.apache.http.util.CharArrayBuffer;
+
 /**
  *  <p>HTTP version, as specified in RFC 2616.</p>
  *  <p>
@@ -201,11 +203,11 @@
      * @see java.lang.Object#toString()
      */
     public String toString() {
-        StringBuffer buffer = new StringBuffer();
+        CharArrayBuffer buffer = new CharArrayBuffer(16);
         buffer.append("HTTP/"); 
-        buffer.append(this.major); 
+        buffer.append(Integer.toString(this.major)); 
         buffer.append('.'); 
-        buffer.append(this.minor); 
+        buffer.append(Integer.toString(this.minor)); 
         return buffer.toString();
     }
 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NameValuePair.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NameValuePair.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NameValuePair.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NameValuePair.java Wed Oct
12 14:32:29 2005
@@ -31,6 +31,7 @@
 
 import java.io.Serializable;
 
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.LangUtils;
 
 /**
@@ -89,7 +90,7 @@
      * @return A string representation.
      */
     public String toString() {
-        StringBuffer buffer = new StringBuffer();
+        CharArrayBuffer buffer = new CharArrayBuffer(32);
         buffer.append(this.name);
         buffer.append(" = ");
         buffer.append(this.value);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestLine.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestLine.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestLine.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestLine.java Wed Oct
12 14:32:29 2005
@@ -32,6 +32,8 @@
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
 
+import org.apache.http.util.CharArrayBuffer;
+
 /**
  * <p>
  * </p>
@@ -76,13 +78,13 @@
     }
 
     public String toString() {
-        StringBuffer sb = new StringBuffer();
-        sb.append(this.method);
-        sb.append(" ");
-        sb.append(this.uri);
-        sb.append(" ");
-        sb.append(this.httpversion);
-        return sb.toString();
+        CharArrayBuffer buffer = new CharArrayBuffer(64);
+        buffer.append(this.method);
+        buffer.append(' ');
+        buffer.append(this.uri);
+        buffer.append(' ');
+        buffer.append(this.httpversion);
+        return buffer.toString();
     }
     
     public static RequestLine parse(final String requestLine) 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/StatusLine.java Wed Oct
12 14:32:29 2005
@@ -29,6 +29,8 @@
 
 package org.apache.http;
 
+import org.apache.http.util.CharArrayBuffer;
+
 /**
  * Represents a Status-Line as returned from a HTTP server.
  *
@@ -179,10 +181,10 @@
     }
 
     public final String toString() {
-        StringBuffer buffer = new StringBuffer();
+    	CharArrayBuffer buffer = new CharArrayBuffer(64);        
         buffer.append(this.httpVersion);
         buffer.append(' ');
-        buffer.append(this.statusCode);
+        buffer.append(Integer.toString(this.statusCode));
         if (this.reasonPhrase != null && !this.reasonPhrase.equals("")) {
             buffer.append(' ');
             buffer.append(this.reasonPhrase);

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/EntityConsumer.java
Wed Oct 12 14:32:29 2005
@@ -42,6 +42,7 @@
 import org.apache.http.NameValuePair;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.util.ByteArrayBuffer;
+import org.apache.http.util.CharArrayBuffer;
 
 /**
  * <p>
@@ -96,7 +97,7 @@
         while((l = instream.read(tmp)) != -1) {
         	buffer.append(tmp, 0, l);
         }
-        return buffer.getBytes();
+        return buffer.toByteArray();
     }
         
     public static String getContentCharSet(final HttpEntity entity) {
@@ -127,6 +128,10 @@
         if (entity.getContentLength() > Integer.MAX_VALUE) {
             throw new IllegalStateException("HTTP entity too large to be buffered in memory");
         }
+        int i = (int)entity.getContentLength();
+        if (i < 0) {
+            i = 4096;
+        }
         String charset = getContentCharSet(entity);
         if (charset == null) {
             charset = defaultCharset;
@@ -135,7 +140,7 @@
             charset = "ISO-8859-1";
         }
         Reader reader = new InputStreamReader(entity.getContent(), charset);
-        StringBuffer buffer = new StringBuffer(); 
+        CharArrayBuffer buffer = new CharArrayBuffer(i); 
         char[] tmp = new char[1024];
         int l;
         while((l = reader.read(tmp)) != -1) {

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/HeaderGroup.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/HeaderGroup.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/HeaderGroup.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/HeaderGroup.java Wed
Oct 12 14:32:29 2005
@@ -34,6 +34,7 @@
 import java.util.List;
 
 import org.apache.http.Header;
+import org.apache.http.util.CharArrayBuffer;
 
 /**
  * A class for combining a set of headers.  This class allows for multiple
@@ -116,8 +117,8 @@
         } else if (headers.length == 1) {
             return headers[0];
         } else {
-            StringBuffer valueBuffer = new StringBuffer(headers[0].getValue());
-            
+        	CharArrayBuffer valueBuffer = new CharArrayBuffer(128);
+        	valueBuffer.append(headers[0].getValue());
             for (int i = 1; i < headers.length; i++) {
                 valueBuffer.append(", ");
                 valueBuffer.append(headers[i].getValue());

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
Wed Oct 12 14:32:29 2005
@@ -212,7 +212,7 @@
             }
         }
         return EncodingUtil.getString(
-                this.linebuffer.getBytes(), 0, this.linebuffer.length(), this.charset);
+                this.linebuffer.getBuffer(), 0, this.linebuffer.length(), this.charset);
     }
     
     private String lineFromReadBuffer(int pos) {

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/io/NIOHttpDataReceiver.java
Wed Oct 12 14:32:29 2005
@@ -40,6 +40,7 @@
 import org.apache.http.io.HttpDataReceiver;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.CharArrayBuffer;
 
 /**
  * <p>
@@ -149,7 +150,7 @@
         int noRead = 0;
         this.chbuffer.clear();
         this.chardecoder.reset();
-        StringBuffer line = new StringBuffer(); 
+        CharArrayBuffer line = new CharArrayBuffer(128); 
         boolean retry = true;
         while (retry) {
             // attempt to find end of line (LF)

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/ByteArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/ByteArrayBuffer.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/ByteArrayBuffer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/ByteArrayBuffer.java
Wed Oct 12 14:32:29 2005
@@ -49,6 +49,12 @@
         this.buffer = new byte[capacity]; 
     }
 
+    private void expand(int newlen) {
+        byte newbuffer[] = new byte[Math.max(this.buffer.length << 1, newlen)];
+        System.arraycopy(this.buffer, 0, newbuffer, 0, this.len);
+        this.buffer = newbuffer;
+    }
+    
     public void append(final byte[] b, int off, int len) {
         if (b == null) {
             return;
@@ -62,9 +68,7 @@
         }
         int newlen = this.len + len;
         if (newlen > this.buffer.length) {
-            byte newbuffer[] = new byte[Math.max(this.buffer.length << 1, newlen)];
-            System.arraycopy(this.buffer, 0, newbuffer, 0, this.len);
-            this.buffer = newbuffer;
+        	expand(newlen);
         }
         System.arraycopy(b, off, this.buffer, this.len, len);
         this.len = newlen;
@@ -74,8 +78,16 @@
     	this.len = 0;
     }
     
-    public byte[] getBytes() {
+    public byte[] getBuffer() {
         return this.buffer;
+    }
+    
+    public byte[] toByteArray() {
+		byte[] b = new byte[this.len]; 
+    	if (this.len > 0) {
+            System.arraycopy(this.buffer, 0, b, 0, this.len);
+    	}
+        return b;
     }
     
     public int byteAt(int i) {

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java?rev=315053&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
Wed Oct 12 14:32:29 2005
@@ -0,0 +1,146 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.util;
+
+/**
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * 
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class CharArrayBuffer  {
+    
+    private char[] buffer;
+    private int len;
+
+    public CharArrayBuffer(int capacity) {
+        super();
+        if (capacity < 0) {
+            throw new IllegalArgumentException("Buffer capacity may not be negative");
+        }
+        this.buffer = new char[capacity]; 
+    }
+
+    private void expand(int newlen) {
+    	char newbuffer[] = new char[Math.max(this.buffer.length << 1, newlen)];
+        System.arraycopy(this.buffer, 0, newbuffer, 0, this.len);
+        this.buffer = newbuffer;
+    }
+    
+    public void append(final char[] b, int off, int len) {
+        if (b == null) {
+            return;
+        }
+        if ((off < 0) || (off > b.length) || (len < 0) ||
+                ((off + len) < 0) || ((off + len) > b.length)) {
+            throw new IndexOutOfBoundsException();
+        }
+        if (len == 0) {
+            return;
+        }
+        int newlen = this.len + len;
+        if (newlen > this.buffer.length) {
+        	expand(newlen);
+        }
+        System.arraycopy(b, off, this.buffer, this.len, len);
+        this.len = newlen;
+    }
+    
+    public void append(String str) {
+    	if (str == null) {
+    	    str = "null";
+    	}
+    	int strlen = str.length();
+    	int newlen = this.len + strlen;
+    	if (newlen > this.buffer.length) {
+        	expand(newlen);
+    	}
+    	str.getChars(0, strlen, this.buffer, this.len);
+    	this.len = newlen;
+    }
+
+    public void append(char ch) {
+    	int newlen = this.len + 1;
+    	if (newlen > this.buffer.length) {
+        	expand(newlen);
+    	}
+    	this.buffer[this.len] = ch;
+    	this.len = newlen;
+    }
+
+    public void append(final Object obj) {
+    	append(String.valueOf(obj));
+    }
+    
+    public void clear() {
+    	this.len = 0;
+    }
+    
+    public char[] getBuffer() {
+        return this.buffer;
+    }
+    
+    public char[] toCharArray() {
+    	char[] b = new char[this.len]; 
+    	if (this.len > 0) {
+            System.arraycopy(this.buffer, 0, b, 0, this.len);
+    	}
+        return b;
+    }
+    
+    public char charAt(int i) {
+        return this.buffer[i];
+    }
+    
+    public int capacity() {
+        return this.buffer.length;
+    }
+    
+    public int length() {
+        return this.len;
+    }
+
+    public void setLength(int len) {
+        if (len < 0 || len > this.buffer.length) {
+            throw new IndexOutOfBoundsException();
+        }
+        this.len = len;
+    }
+    
+    public boolean isEmpty() {
+        return this.len == 0; 
+    }
+    
+    public String toString() {
+    	return new String(this.buffer, 0, this.len);
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/CharArrayBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
Wed Oct 12 14:32:29 2005
@@ -69,7 +69,7 @@
                 // we have continuation folded header
                 // so append value
                 String previousLine = (String) headerLines.remove(headerLines.size() - 1);
-                StringBuffer buffer = new StringBuffer();
+                CharArrayBuffer buffer = new CharArrayBuffer(128);
                 buffer.append(previousLine);
                 buffer.append(' ');
                 buffer.append(line.trim());

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java?rev=315053&r1=315052&r2=315053&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java Wed
Oct 12 14:32:29 2005
@@ -44,6 +44,8 @@
         suite.addTest(TestParameterParser.suite());
         suite.addTest(TestParameterFormatter.suite());
         suite.addTest(TestHeadersParser.suite());
+        suite.addTest(TestByteArrayBuffer.suite());
+        suite.addTest(TestCharArrayBuffer.suite());
         return suite;
     }
 

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java?rev=315053&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
Wed Oct 12 14:32:29 2005
@@ -0,0 +1,174 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.util;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link ByteArrayBuffer}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestByteArrayBuffer extends TestCase {
+
+    public TestByteArrayBuffer(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestByteArrayBuffer.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestByteArrayBuffer.class);
+    }
+
+    public void testConstructor() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(16);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	assertEquals(16, buffer.getBuffer().length);
+    	try {
+    		new ByteArrayBuffer(-1);
+    		fail("IllegalArgumentException should have been thrown");
+    	} catch (IllegalArgumentException ex) {
+    		// expected
+    	}
+    }
+    
+    public void testSimpleAppend() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(16);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	byte[] b1 = buffer.toByteArray();
+    	assertNotNull(b1);
+    	assertEquals(0, b1.length);
+    	assertTrue(buffer.isEmpty());
+    	
+    	byte[] tmp = new byte[] { 1, 2, 3, 4};
+    	buffer.append(tmp, 0, tmp.length);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(4, buffer.length());
+    	assertFalse(buffer.isEmpty());
+    	
+    	byte[] b2 = buffer.toByteArray();
+    	assertNotNull(b2);
+    	assertEquals(4, b2.length);
+    	for (int i = 0; i < tmp.length; i++) {
+        	assertEquals(tmp[i], b2[i]);
+        	assertEquals(tmp[i], buffer.byteAt(i));
+    	}
+    	buffer.clear();
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	assertTrue(buffer.isEmpty());
+    }
+    
+    public void testExpandAppend() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(4);
+    	assertEquals(4, buffer.capacity()); 
+    	
+    	byte[] tmp = new byte[] { 1, 2, 3, 4};
+    	buffer.append(tmp, 0, 2);
+    	buffer.append(tmp, 0, 4);
+    	buffer.append(tmp, 0, 0);
+
+    	assertEquals(8, buffer.capacity()); 
+    	assertEquals(6, buffer.length());
+    	
+    	buffer.append(tmp, 0, 4);
+    	
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(10, buffer.length());
+    }
+    
+    public void testInvalidAppend() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(4);
+    	buffer.append(null, 0, 0);
+
+    	byte[] tmp = new byte[] { 1, 2, 3, 4};
+    	try {
+        	buffer.append(tmp, -1, 0);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 0, -1);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 0, 8);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 10, Integer.MAX_VALUE);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 2, 4);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    }
+
+    public void testSetLength() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(4);
+    	buffer.setLength(2);
+    	assertEquals(2, buffer.length());
+    }
+    
+    public void testSetInvalidLength() throws Exception {
+    	ByteArrayBuffer buffer = new ByteArrayBuffer(4);
+    	try {
+        	buffer.setLength(-2);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.setLength(200);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestByteArrayBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java?rev=315053&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
Wed Oct 12 14:32:29 2005
@@ -0,0 +1,174 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * 
+ * ====================================================================
+ *
+ *  Copyright 1999-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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.util;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link CharArrayBuffer}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestCharArrayBuffer extends TestCase {
+
+    public TestCharArrayBuffer(String testName) {
+        super(testName);
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestCharArrayBuffer.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    public static Test suite() {
+        return new TestSuite(TestCharArrayBuffer.class);
+    }
+
+    public void testConstructor() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(16);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	assertEquals(16, buffer.getBuffer().length);
+    	try {
+    		new CharArrayBuffer(-1);
+    		fail("IllegalArgumentException should have been thrown");
+    	} catch (IllegalArgumentException ex) {
+    		// expected
+    	}
+    }
+    
+    public void testSimpleAppend() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(16);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	char[] b1 = buffer.toCharArray();
+    	assertNotNull(b1);
+    	assertEquals(0, b1.length);
+    	assertTrue(buffer.isEmpty());
+    	
+    	char[] tmp = new char[] { '1', '2', '3', '4'};
+    	buffer.append(tmp, 0, tmp.length);
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(4, buffer.length());
+    	assertFalse(buffer.isEmpty());
+    	
+    	char[] b2 = buffer.toCharArray();
+    	assertNotNull(b2);
+    	assertEquals(4, b2.length);
+    	for (int i = 0; i < tmp.length; i++) {
+        	assertEquals(tmp[i], b2[i]);
+        	assertEquals(tmp[i], buffer.charAt(i));
+    	}
+    	buffer.clear();
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(0, buffer.length());
+    	assertTrue(buffer.isEmpty());
+    }
+    
+    public void testExpandAppend() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(4);
+    	assertEquals(4, buffer.capacity()); 
+    	
+    	char[] tmp = new char[] { '1', '2', '3', '4'};
+    	buffer.append(tmp, 0, 2);
+    	buffer.append(tmp, 0, 4);
+    	buffer.append(tmp, 0, 0);
+
+    	assertEquals(8, buffer.capacity()); 
+    	assertEquals(6, buffer.length());
+    	
+    	buffer.append(tmp, 0, 4);
+    	
+    	assertEquals(16, buffer.capacity()); 
+    	assertEquals(10, buffer.length());
+    }
+    
+    public void testInvalidAppend() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(4);
+    	buffer.append(null, 0, 0);
+
+    	char[] tmp = new char[] { '1', '2', '3', '4'};
+    	try {
+        	buffer.append(tmp, -1, 0);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 0, -1);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 0, 8);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 10, Integer.MAX_VALUE);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.append(tmp, 2, 4);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    }
+
+    public void testSetLength() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(4);
+    	buffer.setLength(2);
+    	assertEquals(2, buffer.length());
+    }
+    
+    public void testSetInvalidLength() throws Exception {
+    	CharArrayBuffer buffer = new CharArrayBuffer(4);
+    	try {
+        	buffer.setLength(-2);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    	try {
+        	buffer.setLength(200);
+    		fail("IndexOutOfBoundsException should have been thrown");
+    	} catch (IndexOutOfBoundsException ex) {
+    		// expected
+    	}
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestCharArrayBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message