hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r165653 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http: HttpEntity.java HttpStreamableEntity.java entity/BufferedHttpEntity.java entity/ByteArrayEntity.java entity/InputStreamEntity.java entity/StringEntity.java impl/BasicHttpEntity.java impl/DefaultEntityWriter.java
Date Mon, 02 May 2005 17:55:35 GMT
Author: olegk
Date: Mon May  2 10:55:34 2005
New Revision: 165653

URL: http://svn.apache.org/viewcvs?rev=165653&view=rev
Log:
writeTo(OutputStream) method moved down to HttpEntity interface, HttpStreamableEntity interface
removed

Removed:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java Mon May
 2 10:55:34 2005
@@ -31,6 +31,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 /**
  * <p>
@@ -52,4 +53,7 @@
     String getContentType();
     
     InputStream getContent() throws IOException;
+    
+    void writeTo(OutputStream outstream) throws IOException;
+    
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
Mon May  2 10:55:34 2005
@@ -32,6 +32,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.http.HttpEntity;
 
@@ -89,5 +90,16 @@
     public boolean isRepeatable() {
         return true;
     }
-
+    
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        if (this.buffer != null) {
+            outstream.write(this.buffer);
+        } else {
+            this.source.writeTo(outstream);
+        }
+    }
+    
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/ByteArrayEntity.java
Mon May  2 10:55:34 2005
@@ -34,7 +34,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.http.HttpStreamableEntity;
+import org.apache.http.HttpEntity;
 
 /**
  * <p>
@@ -45,7 +45,7 @@
  * 
  * @since 4.0
  */
-public class ByteArrayEntity implements HttpStreamableEntity {
+public class ByteArrayEntity implements HttpEntity {
 
     private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/InputStreamEntity.java
Mon May  2 10:55:34 2005
@@ -31,8 +31,10 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.http.HttpEntity;
+import org.apache.http.io.ContentLengthInputStream;
 
 /**
  * <p>
@@ -89,4 +91,19 @@
         return this.content;
     }
         
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        InputStream instream = this.content;
+        if (this.length >= 0) {
+            instream = new ContentLengthInputStream(instream, this.length);
+        }
+        int l;
+        byte[] tmp = new byte[1024];
+        while ((l = instream.read(tmp)) != -1) {
+            outstream.write(tmp, 0, l);
+        }
+    }
+    
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/StringEntity.java
Mon May  2 10:55:34 2005
@@ -34,7 +34,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.http.HttpStreamableEntity;
+import org.apache.http.HttpEntity;
 
 /**
  * <p>
@@ -45,7 +45,7 @@
  * 
  * @since 4.0
  */
-public class StringEntity implements HttpStreamableEntity {
+public class StringEntity implements HttpEntity {
 
     private final static String DEFAULT_CONTENT_TYPE = "text/plain; charset=";
 

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntity.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntity.java
Mon May  2 10:55:34 2005
@@ -29,9 +29,12 @@
 
 package org.apache.http.impl;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.apache.http.HttpMutableEntity;
+import org.apache.http.io.ContentLengthInputStream;
 
 /**
  * <p>
@@ -45,8 +48,8 @@
 public class BasicHttpEntity implements HttpMutableEntity {
     
     private String contenttype = null;
-    private InputStream instream = null;
-    private long contentlen = -1;
+    private InputStream content = null;
+    private long length = -1;
     private boolean chunked = false;
     
     protected BasicHttpEntity() {
@@ -54,7 +57,7 @@
     }
 
     public long getContentLength() {
-        return this.contentlen;
+        return this.length;
     }
 
     public String getContentType() {
@@ -62,7 +65,7 @@
     }
     
     public InputStream getContent() {
-        return this.instream;
+        return this.content;
     }
     
     public boolean isChunked() {
@@ -78,7 +81,7 @@
     }
     
     public void setContentLength(long len) {
-        this.contentlen = len;
+        this.length = len;
     }
     
     public void setContentType(final String contentType) {
@@ -86,7 +89,25 @@
     }
     
     public void setContent(final InputStream instream) {
-        this.instream = instream; 
+        this.content = instream; 
+    }
+    
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        if (this.content == null) {
+            return;
+        }
+        InputStream instream = this.content;
+        if (this.length >= 0) {
+            instream = new ContentLengthInputStream(instream, this.length);
+        }
+        int l;
+        byte[] tmp = new byte[1024];
+        while ((l = instream.read(tmp)) != -1) {
+            outstream.write(tmp, 0, l);
+        }
     }
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java?rev=165653&r1=165652&r2=165653&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java
Mon May  2 10:55:34 2005
@@ -30,16 +30,13 @@
 package org.apache.http.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
-import org.apache.http.HttpStreamableEntity;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolException;
 import org.apache.http.io.ChunkedOutputStream;
-import org.apache.http.io.ContentLengthInputStream;
 import org.apache.http.io.HttpDataOutputStream;
 import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.io.OutputStreamHttpDataTransmitter;
@@ -93,20 +90,7 @@
         if (chunked) {
             outstream = new ChunkedOutputStream(outstream);
         }
-        if (entity instanceof HttpStreamableEntity) {
-            ((HttpStreamableEntity)entity).writeTo(outstream);
-        } else {
-            InputStream instream = entity.getContent();
-            long len = entity.getContentLength();
-            if (len >= 0) {
-                instream = new ContentLengthInputStream(instream, len);
-            }
-            int l;
-            byte[] tmp = new byte[1024];
-            while ((l = instream.read(tmp)) != -1) {
-                outstream.write(tmp, 0, l);
-            }
-        }
+        entity.writeTo(outstream);
         if (outstream instanceof ChunkedOutputStream) {
             ((ChunkedOutputStream) outstream).finish();
         }



Mime
View raw message