You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2006/04/01 22:01:00 UTC

svn commit: r390741 - in /jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http: HeaderElement.java io/ChunkedInputStream.java

Author: olegk
Date: Sat Apr  1 12:00:59 2006
New Revision: 390741

URL: http://svn.apache.org/viewcvs?rev=390741&view=rev
Log:
Changed to use <array>#clone() to copy the content of an array instead of System.arraycopy()

Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java?rev=390741&r1=390740&r2=390741&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java Sat Apr  1 12:00:59 2006
@@ -88,6 +88,26 @@
     private final String value;
     private final NameValuePair[] parameters;
 
+    private HeaderElement(final NameValuePair[] nvps) {
+        super();
+        if (nvps.length > 0) {
+            NameValuePair nvp = nvps[0];
+            this.name = nvp.getName();
+            this.value = nvp.getValue();
+            int len = nvps.length - 1; 
+            if (len > 0) {
+                this.parameters = new NameValuePair[len];
+                System.arraycopy(nvps, 1, this.parameters, 0, len);
+            } else {
+                this.parameters = new NameValuePair[] {}; 
+            }
+        } else {
+            this.name = "";
+            this.value = null;
+            this.parameters = new NameValuePair[] {}; 
+        }
+    }
+    
     /**
      * Constructor with name, value and parameters.
      *
@@ -106,8 +126,7 @@
         this.name = name;
         this.value = value;
         if (parameters != null) {
-            this.parameters = new NameValuePair[parameters.length];
-            System.arraycopy(parameters, 0, this.parameters, 0, parameters.length);
+            this.parameters = (NameValuePair[])parameters.clone();
         } else {
             this.parameters = new NameValuePair[] {};
         }
@@ -148,9 +167,7 @@
      * @return parameters as an array of {@link NameValuePair}s
      */
     public NameValuePair[] getParameters() {
-        NameValuePair[] acopy = new NameValuePair[this.parameters.length]; 
-        System.arraycopy(this.parameters, 0, acopy, 0, this.parameters.length);
-        return acopy;
+        return (NameValuePair[])this.parameters.clone();
     }
 
     // --------------------------------------------------------- Public Methods
@@ -246,20 +263,7 @@
             throw new IndexOutOfBoundsException();
         }
         NameValuePair[] nvps = NameValuePair.parseAll(buffer, indexFrom, indexTo);
-        if (nvps.length > 0) {
-            NameValuePair nvp = nvps[0];
-            String name = nvp.getName();
-            String value = nvp.getValue();
-            NameValuePair[] params = null;
-            int len = nvps.length - 1; 
-            if (len > 0) {
-                params = new NameValuePair[len];
-                System.arraycopy(nvps, 1, params, 0, len);
-            }
-            return new HeaderElement(name, value, params);
-        } else {
-            return new HeaderElement("", null, null);
-        }
+        return new HeaderElement(nvps);
     }
 
     public static final HeaderElement parse(final String s) {

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java?rev=390741&r1=390740&r2=390741&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java Sat Apr  1 12:00:59 2006
@@ -318,9 +318,7 @@
     }
 
     public Header[] getFooters() {
-        Header[] acopy = new Header[this.footers.length]; 
-        System.arraycopy(this.footers, 0, acopy, 0, this.footers.length);
-        return acopy;
+        return (Header[])this.footers.clone();
     }
     
     /**