hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r355230 - in /jakarta/httpcomponents/trunk/http-core/src: java/org/apache/http/io/ByteArrayBuffer.java test/org/apache/http/io/TestByteArrayBuffer.java
Date Thu, 08 Dec 2005 21:53:28 GMT
Author: olegk
Date: Thu Dec  8 13:53:20 2005
New Revision: 355230

URL: http://svn.apache.org/viewcvs?rev=355230&view=rev
Log:
Added ByteArrayBuffer#append(int) method

Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ByteArrayBuffer.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestByteArrayBuffer.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ByteArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ByteArrayBuffer.java?rev=355230&r1=355229&r2=355230&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ByteArrayBuffer.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ByteArrayBuffer.java
Thu Dec  8 13:53:20 2005
@@ -74,6 +74,15 @@
         this.len = newlen;
     }
 
+    public void append(int b) {
+        int newlen = this.len + 1;
+        if (newlen > this.buffer.length) {
+            expand(newlen);
+        }
+        this.buffer[this.len] = (byte)b;
+        this.len = newlen;
+    }
+
     public void clear() {
     	this.len = 0;
     }

Modified: jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestByteArrayBuffer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestByteArrayBuffer.java?rev=355230&r1=355229&r2=355230&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestByteArrayBuffer.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestByteArrayBuffer.java
Thu Dec  8 13:53:20 2005
@@ -152,6 +152,22 @@
     	}
     }
 
+    public void testAppendOneByte() throws Exception {
+        ByteArrayBuffer buffer = new ByteArrayBuffer(4);
+        assertEquals(4, buffer.capacity()); 
+        
+        byte[] tmp = new byte[] { 1, 127, -1, -128, 1, -2};
+        for (int i = 0; i < tmp.length; i++) {
+            buffer.append(tmp[i]);
+        }
+        assertEquals(8, buffer.capacity()); 
+        assertEquals(6, buffer.length());
+        
+        for (int i = 0; i < tmp.length; i++) {
+            assertEquals(tmp[i], buffer.byteAt(i));
+        }
+    }
+    
     public void testSetLength() throws Exception {
     	ByteArrayBuffer buffer = new ByteArrayBuffer(4);
     	buffer.setLength(2);



Mime
View raw message