hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r940997 - in /httpcomponents/httpcore/trunk: ./ httpcore/src/main/java/org/apache/http/message/ httpcore/src/main/java/org/apache/http/util/ httpcore/src/test/java/org/apache/http/message/ httpcore/src/test/java/org/apache/http/util/
Date Tue, 04 May 2010 18:46:58 GMT
Author: olegk
Date: Tue May  4 18:46:57 2010
New Revision: 940997

URL: http://svn.apache.org/viewvc?rev=940997&view=rev
Log:
ByteArrayBuffer, CharArrayBuffer, BasicHeader, BufferedHeader, HeaderGroup made Serializable

Added:
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBufferedHeader.java
Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicHeader.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BufferedHeader.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeader.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestByteArrayBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestCharArrayBuffer.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue May  4 18:46:57 2010
@@ -1,3 +1,8 @@
+Changes since 4.1-BETA1 
+
+* ByteArrayBuffer, CharArrayBuffer, BasicHeader, BufferedHeader, HeaderGroup made Serializable.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 Release 4.1-BETA1
 -------------------
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicHeader.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicHeader.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicHeader.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,8 @@
 
 package org.apache.http.message;
 
+import java.io.Serializable;
+
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.ParseException;
@@ -36,8 +38,10 @@ import org.apache.http.ParseException;
  *
  * @since 4.0
  */
-public class BasicHeader implements Header, Cloneable {
+public class BasicHeader implements Header, Cloneable, Serializable {
 
+    private static final long serialVersionUID = -5427236326487562174L;
+    
     private final String name;
     private final String value;
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BufferedHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BufferedHeader.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BufferedHeader.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BufferedHeader.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,8 @@
 
 package org.apache.http.message;
 
+import java.io.Serializable;
+
 import org.apache.http.FormattedHeader;
 import org.apache.http.HeaderElement;
 import org.apache.http.ParseException;
@@ -38,7 +40,9 @@ import org.apache.http.util.CharArrayBuf
  *
  * @since 4.0
  */
-public class BufferedHeader implements FormattedHeader, Cloneable {
+public class BufferedHeader implements FormattedHeader, Cloneable, Serializable {
+
+    private static final long serialVersionUID = -2768352615787625448L;
 
     /**
      * Header name.

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,7 @@
 
 package org.apache.http.message;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -43,7 +44,9 @@ import org.apache.http.util.CharArrayBuf
  *
  * @since 4.0
  */
-public class HeaderGroup implements Cloneable {
+public class HeaderGroup implements Cloneable, Serializable {
+
+    private static final long serialVersionUID = 2608834160639271617L;
 
     /** The list of headers for this group, in the order in which they were added */
     private final List headers;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
Tue May  4 18:46:57 2010
@@ -27,12 +27,16 @@
 
 package org.apache.http.util;
 
+import java.io.Serializable;
+
 /**
  * A resizable byte array.
  *
  * @since 4.0
  */
-public final class ByteArrayBuffer  {
+public final class ByteArrayBuffer implements Serializable {
+
+    private static final long serialVersionUID = 4359112959524048036L;
 
     private byte[] buffer;
     private int len;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,8 @@
 
 package org.apache.http.util;
 
+import java.io.Serializable;
+
 import org.apache.http.protocol.HTTP;
 
 /**
@@ -34,7 +36,9 @@ import org.apache.http.protocol.HTTP;
  *
  * @since 4.0
  */
-public final class CharArrayBuffer  {
+public final class CharArrayBuffer implements Serializable {
+
+    private static final long serialVersionUID = -6208952725094867135L;
 
     private char[] buffer;
     private int len;

Added: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBufferedHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBufferedHeader.java?rev=940997&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBufferedHeader.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBufferedHeader.java
Tue May  4 18:46:57 2010
@@ -0,0 +1,111 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * 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.message;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.http.HeaderElement;
+import org.apache.http.util.CharArrayBuffer;
+
+/**
+ * Unit tests for {@link BufferedHeader}.
+ *
+ */
+public class TestBufferedHeader extends TestCase {
+
+    public TestBufferedHeader(String testName) {
+        super(testName);
+    }
+
+    public void testBasicConstructor() {
+        CharArrayBuffer buf = new CharArrayBuffer(32);
+        buf.append("name: value");
+        BufferedHeader header = new BufferedHeader(buf);
+        assertEquals("name", header.getName());
+        assertEquals("value", header.getValue());
+        assertSame(buf, header.getBuffer());
+        assertEquals(5, header.getValuePos());
+    }
+
+    public void testInvalidName() {
+        try {
+            new BufferedHeader(null);
+            fail("IllegalArgumentException should have been thrown");
+        } catch (IllegalArgumentException ex) {
+            //expected
+        }
+    }
+
+    public void testHeaderElements() {
+        CharArrayBuffer buf = new CharArrayBuffer(32);
+        buf.append("name: element1 = value1, element2; param1 = value1, element3");
+        BufferedHeader header = new BufferedHeader(buf);
+        HeaderElement[] elements = header.getElements();
+        assertNotNull(elements);
+        assertEquals(3, elements.length);
+        assertEquals("element1", elements[0].getName());
+        assertEquals("value1", elements[0].getValue());
+        assertEquals("element2", elements[1].getName());
+        assertEquals(null, elements[1].getValue());
+        assertEquals("element3", elements[2].getName());
+        assertEquals(null, elements[2].getValue());
+        assertEquals(1, elements[1].getParameters().length);
+    }
+
+    public void testCloning() throws Exception {
+        CharArrayBuffer buf = new CharArrayBuffer(32);
+        buf.append("name: value");
+        BufferedHeader orig = new BufferedHeader(buf);
+        BufferedHeader clone = (BufferedHeader) orig.clone();
+        assertEquals(orig.getName(), clone.getName());
+        assertEquals(orig.getValue(), clone.getValue());
+    }
+
+    public void testSerialization() throws Exception {
+        CharArrayBuffer buf = new CharArrayBuffer(32);
+        buf.append("name: value");
+        BufferedHeader orig = new BufferedHeader(buf);
+        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+        outstream.writeObject(orig);
+        outstream.close();
+        byte[] raw = outbuffer.toByteArray();
+        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+        ObjectInputStream instream = new ObjectInputStream(inbuffer);
+        BufferedHeader clone = (BufferedHeader) instream.readObject();
+        assertEquals(orig.getName(), clone.getName());
+        assertEquals(orig.getValue(), clone.getValue());
+    }
+
+}
+

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeader.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeader.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeader.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,11 @@
 
 package org.apache.http.message;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.TestCase;
 
 import org.apache.http.Header;
@@ -96,5 +101,19 @@ public class TestHeader extends TestCase
         assertEquals(orig.getValue(), clone.getValue());
     }
 
+    public void testSerialization() throws Exception {
+        BasicHeader orig = new BasicHeader("name1", "value1");
+        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+        outstream.writeObject(orig);
+        outstream.close();
+        byte[] raw = outbuffer.toByteArray();
+        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+        ObjectInputStream instream = new ObjectInputStream(inbuffer);
+        BasicHeader clone = (BasicHeader) instream.readObject();
+        assertEquals(orig.getName(), clone.getName());
+        assertEquals(orig.getValue(), clone.getValue());
+    }
+
 }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,10 @@
 
 package org.apache.http.message;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.Iterator;
 
 import junit.framework.TestCase;
@@ -171,8 +175,34 @@ public class TestHeaderGroup extends Tes
         assertNotNull(headers2);
         assertEquals(headers1.length, headers2.length);
         for (int i = 0; i < headers1.length; i++) {
-            assertEquals(headers1[i], headers2[i]);
+            assertEquals(headers1[i].getName(), headers2[i].getName());
+            assertEquals(headers1[i].getValue(), headers2[i].getValue());
         }
     }
 
+    public void testSerialization() throws Exception {
+        HeaderGroup orig = new HeaderGroup();
+        Header header1 = new BasicHeader("name", "value1");
+        Header header2 = new BasicHeader("name", "value2");
+        Header header3 = new BasicHeader("name", "value3");
+        orig.setHeaders(new Header[] { header1, header2, header3 });
+        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+        outstream.writeObject(orig);
+        outstream.close();
+        byte[] raw = outbuffer.toByteArray();
+        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+        ObjectInputStream instream = new ObjectInputStream(inbuffer);
+        HeaderGroup clone = (HeaderGroup) instream.readObject();
+        Header[] headers1 = orig.getAllHeaders();
+        Header[] headers2 = clone.getAllHeaders();
+        assertNotNull(headers1);
+        assertNotNull(headers2);
+        assertEquals(headers1.length, headers2.length);
+        for (int i = 0; i < headers1.length; i++) {
+            assertEquals(headers1[i].getName(), headers2[i].getName());
+            assertEquals(headers1[i].getValue(), headers2[i].getValue());
+        }
+    }
+    
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestByteArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestByteArrayBuffer.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestByteArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestByteArrayBuffer.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,11 @@
 
 package org.apache.http.util;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.TestCase;
 
 /**
@@ -271,4 +276,27 @@ public class TestByteArrayBuffer extends
         }
     }
 
+    public void testSerialization() throws Exception {
+        ByteArrayBuffer orig = new ByteArrayBuffer(32);
+        orig.append(1);
+        orig.append(2);
+        orig.append(3);
+        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+        outstream.writeObject(orig);
+        outstream.close();
+        byte[] raw = outbuffer.toByteArray();
+        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+        ObjectInputStream instream = new ObjectInputStream(inbuffer);
+        ByteArrayBuffer clone = (ByteArrayBuffer) instream.readObject();
+        assertEquals(orig.capacity(), clone.capacity());
+        assertEquals(orig.length(), clone.length());
+        byte[] data = clone.toByteArray();
+        assertNotNull(data);
+        assertEquals(3, data.length);
+        assertEquals(1, data[0]);
+        assertEquals(2, data[1]);
+        assertEquals(3, data[2]);
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestCharArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestCharArrayBuffer.java?rev=940997&r1=940996&r2=940997&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestCharArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestCharArrayBuffer.java
Tue May  4 18:46:57 2010
@@ -27,6 +27,11 @@
 
 package org.apache.http.util;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.TestCase;
 
 /**
@@ -352,4 +357,27 @@ public class TestCharArrayBuffer extends
         }
     }
 
+    public void testSerialization() throws Exception {
+        CharArrayBuffer orig = new CharArrayBuffer(32);
+        orig.append('a');
+        orig.append('b');
+        orig.append('c');
+        ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+        ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+        outstream.writeObject(orig);
+        outstream.close();
+        byte[] raw = outbuffer.toByteArray();
+        ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+        ObjectInputStream instream = new ObjectInputStream(inbuffer);
+        CharArrayBuffer clone = (CharArrayBuffer) instream.readObject();
+        assertEquals(orig.capacity(), clone.capacity());
+        assertEquals(orig.length(), clone.length());
+        char[] data = clone.toCharArray();
+        assertNotNull(data);
+        assertEquals(3, data.length);
+        assertEquals('a', data[0]);
+        assertEquals('b', data[1]);
+        assertEquals('c', data[2]);
+    }
+
 }



Mime
View raw message