hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r164895 - in /jakarta/httpclient/trunk/http-common/src: java/org/apache/http/ java/org/apache/http/entity/ java/org/apache/http/impl/ test/org/apache/http/impl/
Date Tue, 26 Apr 2005 21:43:59 GMT
Author: olegk
Date: Tue Apr 26 14:43:58 2005
New Revision: 164895

URL: http://svn.apache.org/viewcvs?rev=164895&view=rev
Log:
Removed HttpIncomingEntity interface and replaced HttpOutcomingEntity interface with HttpStreamableEntity
Added EntityWriter interface and its default impl

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java
      - copied, changed from r164760, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java
      - copied, changed from r164760, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java   (with props)
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java   (with props)
Removed:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpIncomingEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableIncomingEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableEntity.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/EntityConsumer.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/DefaultEntityGenerator.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityGenerator.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultEntityGenerator.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultResponseConsumedWatcher.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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -29,6 +29,9 @@
 
 package org.apache.http;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 /**
  * <p>
  * </p>
@@ -48,4 +51,5 @@
     
     String getContentType();
     
+    InputStream getContent() throws IOException;
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableEntity.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpMutableEntity.java Tue Apr 26 14:43:58 2005
@@ -29,6 +29,8 @@
 
 package org.apache.http;
 
+import java.io.InputStream;
+
 /**
  * <p>
  * </p>
@@ -46,4 +48,5 @@
     
     void setContentLength(long len);
     
+    void setContent(InputStream instream);
 }

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java (from r164760, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java&r1=164760&r2=164895&rev=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpOutgoingEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpStreamableEntity.java Tue Apr 26 14:43:58 2005
@@ -41,7 +41,7 @@
  * 
  * @since 4.0
  */
-public interface HttpOutgoingEntity extends HttpEntity {
+public interface HttpStreamableEntity extends HttpEntity {
 
     void writeTo(OutputStream outstream) throws IOException;
     

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java (from r164760, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java&r1=164760&r2=164895&rev=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpIncomingEntity.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/entity/BufferedHttpEntity.java Tue Apr 26 14:43:58 2005
@@ -33,7 +33,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.http.HttpIncomingEntity;
+import org.apache.http.HttpEntity;
 
 /**
  * <p>
@@ -44,12 +44,12 @@
  * 
  * @since 4.0
  */
-public class BufferedHttpIncomingEntity implements HttpIncomingEntity {
+public class BufferedHttpEntity implements HttpEntity {
     
-    private final HttpIncomingEntity source;
+    private final HttpEntity source;
     private final byte[] buffer;
     
-    public BufferedHttpIncomingEntity(final HttpIncomingEntity entity) throws IOException {
+    public BufferedHttpEntity(final HttpEntity entity) throws IOException {
         super();
         if (entity == null) {
             throw new IllegalArgumentException("HTTP entity may not be null");
@@ -74,11 +74,11 @@
         return this.source.getContentType();
     }
     
-    public InputStream getInputStream() {
+    public InputStream getContent() throws IOException {
         if (this.buffer != null) {
             return new ByteArrayInputStream(this.buffer);
         } else {
-            return this.source.getInputStream();
+            return this.source.getContent();
         }
     }
     

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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -29,10 +29,12 @@
 
 package org.apache.http.entity;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.http.HttpOutgoingEntity;
+import org.apache.http.HttpStreamableEntity;
 
 /**
  * <p>
@@ -43,11 +45,11 @@
  * 
  * @since 4.0
  */
-public class ByteArrayEntity implements HttpOutgoingEntity {
+public class ByteArrayEntity implements HttpStreamableEntity {
 
     private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
 
-    private final byte[] source;
+    private final byte[] content;
     private String contentType = DEFAULT_CONTENT_TYPE;
     private boolean chunked = false;
 
@@ -56,7 +58,7 @@
         if (b == null) {
             throw new IllegalArgumentException("Source byte array may not be null");
         }
-        this.source = b;
+        this.content = b;
     }
 
     public boolean isRepeatable() {
@@ -72,7 +74,7 @@
     }
 
     public long getContentLength() {
-        return this.source.length;
+        return this.content.length;
     }
     
     public String getContentType() {
@@ -83,11 +85,15 @@
         this.contentType = s;
     }
 
+    public InputStream getContent() {
+        return new ByteArrayInputStream(this.content);
+    }
+    
     public void writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
-        outstream.write(this.source);
+        outstream.write(this.content);
         outstream.flush();
     }
 

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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -38,7 +38,6 @@
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpIncomingEntity;
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;
@@ -56,7 +55,7 @@
 public class EntityConsumer {
     
     private final HttpMessage message;
-    private final HttpIncomingEntity entity;
+    private final HttpEntity entity;
     
     public EntityConsumer(final HttpResponse response) {
         super();
@@ -64,7 +63,7 @@
             throw new IllegalArgumentException("HTTP response may not be null");
         }
         this.message = response;
-        this.entity = (HttpIncomingEntity)response.getEntity();
+        this.entity = response.getEntity();
     }
 
     public EntityConsumer(final HttpEntityEnclosingRequest request) {
@@ -73,14 +72,14 @@
             throw new IllegalArgumentException("HTTP request may not be null");
         }
         this.message = request;
-        this.entity = (HttpIncomingEntity)request.getEntity();
+        this.entity = request.getEntity();
     }
 
-    public static byte[] toByteArray(final HttpIncomingEntity entity) throws IOException {
+    public static byte[] toByteArray(final HttpEntity entity) throws IOException {
         if (entity == null) {
             throw new IllegalArgumentException("HTTP entity may not be null");
         }
-        InputStream instream = entity.getInputStream();
+        InputStream instream = entity.getContent();
         if (instream == null) {
             return new byte[] {};
         }
@@ -118,11 +117,11 @@
     }
 
     public static String toString(
-            final HttpIncomingEntity entity, final String defaultCharset) throws IOException {
+            final HttpEntity entity, final String defaultCharset) throws IOException {
         if (entity == null) {
             throw new IllegalArgumentException("HTTP entity may not be null");
         }
-        if (entity.getInputStream() == null) {
+        if (entity.getContent() == null) {
             return "";
         }
         if (entity.getContentLength() > Integer.MAX_VALUE) {
@@ -135,7 +134,7 @@
         if (charset == null) {
             charset = "ISO-8859-1";
         }
-        Reader reader = new InputStreamReader(entity.getInputStream(), charset);
+        Reader reader = new InputStreamReader(entity.getContent(), charset);
         StringBuffer buffer = new StringBuffer(); 
         char[] tmp = new char[1024];
         int l;
@@ -145,7 +144,7 @@
         return buffer.toString();
     }
 
-    public static String toString(final HttpIncomingEntity entity) throws IOException {
+    public static String toString(final HttpEntity entity) throws IOException {
         return toString(entity, null);
     }
 

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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -31,10 +31,8 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
-import org.apache.http.HttpOutgoingEntity;
-import org.apache.http.io.ContentLengthInputStream;
+import org.apache.http.HttpEntity;
 
 /**
  * <p>
@@ -45,11 +43,11 @@
  * 
  * @since 4.0
  */
-public class InputStreamEntity implements HttpOutgoingEntity {
+public class InputStreamEntity implements HttpEntity {
 
     private final static String DEFAULT_CONTENT_TYPE = "application/octet-stream";
 
-    private final InputStream source;
+    private final InputStream content;
     private final long length;
     private String contentType = DEFAULT_CONTENT_TYPE;
     private boolean chunked = false;
@@ -59,7 +57,7 @@
         if (instream == null) {
             throw new IllegalArgumentException("Source input stream may not be null");
         }
-        this.source = instream;
+        this.content = instream;
         this.length = length;
     }
 
@@ -87,20 +85,8 @@
         this.contentType = s;
     }
 
-    public void writeTo(final OutputStream outstream) throws IOException {
-        if (outstream == null) {
-            throw new IllegalArgumentException("Output stream may not be null");
-        }
-        InputStream instream = this.source;
-        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);
-        }
-        outstream.flush();
+    public InputStream getContent() throws IOException {
+        return this.content;
     }
-
+        
 }

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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -29,10 +29,12 @@
 
 package org.apache.http.entity;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.http.HttpOutgoingEntity;
+import org.apache.http.HttpStreamableEntity;
 
 /**
  * <p>
@@ -43,11 +45,11 @@
  * 
  * @since 4.0
  */
-public class StringEntity implements HttpOutgoingEntity {
+public class StringEntity implements HttpStreamableEntity {
 
     private final static String DEFAULT_CONTENT_TYPE = "text/plain; charset=";
 
-    private final String source;
+    private final String content;
     private String contentType = null;
     private boolean chunked = false;
 
@@ -56,7 +58,7 @@
         if (s == null) {
             throw new IllegalArgumentException("Source string may not be null");
         }
-        this.source = s;
+        this.content = s;
         if (charset != null) {
             this.contentType = DEFAULT_CONTENT_TYPE + charset;
         }
@@ -79,7 +81,7 @@
     }
 
     public long getContentLength() {
-        return this.source.length();
+        return this.content.length();
     }
     
     public String getContentType() {
@@ -89,13 +91,18 @@
     public void setContentType(final String s) {
         this.contentType = s;
     }
-
+    
+    public InputStream getContent() throws IOException {
+        String charset = EntityConsumer.getContentCharSet(this);
+        return new ByteArrayInputStream(this.content.getBytes(charset));
+    }
+    
     public void writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
         String charset = EntityConsumer.getContentCharSet(this);
-        byte[] content = this.source.getBytes(charset);
+        byte[] content = this.content.getBytes(charset);
         outstream.write(content);
         outstream.flush();
     }

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=164895&r1=164894&r2=164895&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 Tue Apr 26 14:43:58 2005
@@ -31,7 +31,7 @@
 
 import java.io.InputStream;
 
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 
 /**
  * <p>
@@ -42,7 +42,7 @@
  * 
  * @since 4.0
  */
-public class BasicHttpEntity implements HttpMutableIncomingEntity {
+public class BasicHttpEntity implements HttpMutableEntity {
     
     private String contenttype = null;
     private InputStream instream = null;
@@ -61,7 +61,7 @@
         return this.contenttype;
     }
     
-    public InputStream getInputStream() {
+    public InputStream getContent() {
         return this.instream;
     }
     
@@ -85,7 +85,7 @@
         this.contenttype = contentType;
     }
     
-    public void setInputStream(final InputStream instream) {
+    public void setContent(final InputStream instream) {
         this.instream = instream; 
     }
     

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityGenerator.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityGenerator.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityGenerator.java Tue Apr 26 14:43:58 2005
@@ -36,7 +36,7 @@
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpException;
 import org.apache.http.HttpMessage;
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 import org.apache.http.ProtocolException;
 import org.apache.http.io.ChunkedInputStream;
 import org.apache.http.io.ContentLengthInputStream;
@@ -208,7 +208,7 @@
         }
     }
     
-    public HttpMutableIncomingEntity generate(
+    public HttpMutableEntity generate(
             final HttpDataReceiver datareceiver,
             final HttpMessage message) throws HttpException, IOException {
         if (datareceiver == null) {
@@ -218,7 +218,7 @@
             throw new IllegalArgumentException("HTTP message may not be null");
         }
 
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         
         HttpParams params = message.getParams(); 
         boolean strict = params.isParameterTrue(HttpProtocolParams.STRICT_TRANSFER_ENCODING);
@@ -246,19 +246,19 @@
             if (IDENTITY_ENCODING.equalsIgnoreCase(transferEncodingHeader.getValue())) {
                 entity.setChunked(false);
                 entity.setContentLength(-1);
-                entity.setInputStream(getRawInputStream(datareceiver));                            
+                entity.setContent(getRawInputStream(datareceiver));                            
             } else if ((len > 0) && (CHUNKED_ENCODING.equalsIgnoreCase(encodings[len - 1].getName()))) { 
                 entity.setChunked(true);
                 entity.setContentLength(-1);
                 // if response body is empty
                 HttpConnectionParams connparams = new HttpConnectionParams(params); 
                 if (datareceiver.isDataAvailable(connparams.getSoTimeout())) {
-                    entity.setInputStream(new ChunkedInputStream(datareceiver));
+                    entity.setContent(new ChunkedInputStream(datareceiver));
                 } else {
                     if (strict) {
                         throw new ProtocolException("Chunk-encoded body declared but not sent");
                     }
-                    entity.setInputStream(null);                            
+                    entity.setContent(null);                            
                 }
             } else {
                 if (strict) {
@@ -266,7 +266,7 @@
                 }
                 entity.setChunked(false);
                 entity.setContentLength(-1);
-                entity.setInputStream(getRawInputStream(datareceiver));                            
+                entity.setContent(getRawInputStream(datareceiver));                            
             }
         } else if (contentLengthHeader != null) {
             long contentlen = -1;
@@ -292,11 +292,11 @@
             if (contentlen >= 0) {
                 instream = new ContentLengthInputStream(instream, contentlen);
             }
-            entity.setInputStream(instream);
+            entity.setContent(instream);
         } else {
             entity.setChunked(false);
             entity.setContentLength(-1);
-            entity.setInputStream(getRawInputStream(datareceiver));                            
+            entity.setContent(getRawInputStream(datareceiver));                            
         }
         if (contentTypeHeader != null) {
             entity.setContentType(contentTypeHeader.getValue());    

Added: 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=164895&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java Tue Apr 26 14:43:58 2005
@@ -0,0 +1,116 @@
+/*
+ * $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.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;
+
+/**
+ * <p>
+ * </p>
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: $
+ * 
+ * @since 4.0
+ */
+public class DefaultEntityWriter implements EntityWriter {
+
+    public DefaultEntityWriter() {
+        super();
+    }
+
+    private OutputStream getRawOutputStream(final HttpDataTransmitter datatransmitter) {
+        // This is a (quite ugly) performance hack
+        if (datatransmitter instanceof OutputStreamHttpDataTransmitter) {
+            // If we are dealing with the compatibility wrapper
+            // Get the original input stream
+            return  ((OutputStreamHttpDataTransmitter)datatransmitter).getOutputStream();
+        } else {
+            return new HttpDataOutputStream(datatransmitter);
+        }
+    }
+
+    public void write(
+            final HttpEntity entity,
+            final HttpVersion version,
+            final HttpDataTransmitter datatransmitter) throws HttpException, IOException {
+        if (entity == null) {
+            throw new IllegalArgumentException("HTTP entity may not be null");
+        }
+        if (version == null) {
+            throw new IllegalArgumentException("HTTP version may not be null");
+        }
+        if (datatransmitter == null) {
+            throw new IllegalArgumentException("HTTP data transmitter may not be null");
+        }
+        boolean chunked = entity.isChunked() || entity.getContentLength() < 0;  
+        if (chunked && version.lessEquals(HttpVersion.HTTP_1_0)) {
+            throw new ProtocolException(
+                    "Chunked transfer encoding not allowed for " + version);
+        }
+        OutputStream outstream = getRawOutputStream(datatransmitter);
+        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);
+            }
+        }
+        if (outstream instanceof ChunkedOutputStream) {
+            ((ChunkedOutputStream) outstream).finish();
+        }
+        outstream.flush();
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultEntityWriter.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpClientConnection.java Tue Apr 26 14:43:58 2005
@@ -31,7 +31,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.Socket;
 
@@ -40,9 +39,8 @@
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 import org.apache.http.HttpMutableResponse;
-import org.apache.http.HttpOutgoingEntity;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -51,8 +49,6 @@
 import org.apache.http.ProtocolException;
 import org.apache.http.ProtocolSocketFactory;
 import org.apache.http.StatusLine;
-import org.apache.http.io.ChunkedOutputStream;
-import org.apache.http.io.HttpDataOutputStream;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.util.HeadersParser;
@@ -188,22 +184,11 @@
         if (request.getEntity() == null) {
             return;
         }
-        HttpOutgoingEntity entity = (HttpOutgoingEntity)request.getEntity();
-        HttpVersion ver = request.getRequestLine().getHttpVersion();
-        boolean chunked = entity.isChunked() || entity.getContentLength() < 0;  
-        if (chunked && ver.lessEquals(HttpVersion.HTTP_1_0)) {
-            throw new ProtocolException(
-                    "Chunked transfer encoding not allowed for " + ver);
-        }
-        OutputStream outstream = new HttpDataOutputStream(this.datatransmitter);
-        if (chunked) {
-            outstream = new ChunkedOutputStream(outstream);
-        }
-        entity.writeTo(outstream);
-        if (outstream instanceof ChunkedOutputStream) {
-            ((ChunkedOutputStream) outstream).finish();
-        }
-        outstream.flush();
+        EntityWriter entitywriter = new DefaultEntityWriter();
+        entitywriter.write(
+                request.getEntity(),
+                request.getRequestLine().getHttpVersion(),
+                this.datatransmitter);
     }
     
     public HttpResponse receiveResponse(final HttpRequest request) 
@@ -280,22 +265,22 @@
     protected void processResponseBody(
             final HttpMutableResponse response) throws HttpException, IOException {
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpMutableIncomingEntity entity = entitygen.generate(this.datareceiver, response);
+        HttpMutableEntity entity = entitygen.generate(this.datareceiver, response);
         if (canResponseHaveBody(response)) {
             // if there is a result - ALWAYS wrap it in an observer which will
             // close the underlying stream as soon as it is consumed, and notify
             // the watcher that the stream has been consumed.
-            InputStream instream = entity.getInputStream();
+            InputStream instream = entity.getContent();
             instream = new AutoCloseInputStream(
                     instream, new DefaultResponseConsumedWatcher(this, response));
-            entity.setInputStream(instream);
+            entity.setContent(instream);
         } else {
             if (entity.isChunked() || entity.getContentLength() > 0) {
                 if (isWarnEnabled()) {
                     warn("This response may not have a response body");
                 }
             }
-            entity.setInputStream(null);
+            entity.setContent(null);
         }
         response.setEntity(entity);
     }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java Tue Apr 26 14:43:58 2005
@@ -30,7 +30,6 @@
 package org.apache.http.impl;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.net.Socket;
 
 import org.apache.http.Header;
@@ -39,16 +38,12 @@
 import org.apache.http.HttpMutableEntityEnclosingRequest;
 import org.apache.http.HttpMutableRequest;
 import org.apache.http.HttpMutableResponse;
-import org.apache.http.HttpOutgoingEntity;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpServerConnection;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
 import org.apache.http.RequestLine;
-import org.apache.http.io.ChunkedOutputStream;
-import org.apache.http.io.HttpDataOutputStream;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.HeadersParser;
 
@@ -203,22 +198,11 @@
         if (response.getEntity() == null) {
             return;
         }
-        HttpOutgoingEntity entity = (HttpOutgoingEntity)response.getEntity();
-        HttpVersion ver = response.getStatusLine().getHttpVersion();
-        boolean chunked = entity.isChunked() || entity.getContentLength() < 0;  
-        if (chunked && ver.lessEquals(HttpVersion.HTTP_1_0)) {
-            throw new ProtocolException(
-                    "Chunked transfer encoding not allowed for " + ver);
-        }
-        OutputStream outstream = new HttpDataOutputStream(this.datatransmitter);
-        if (chunked) {
-            outstream = new ChunkedOutputStream(outstream);
-        }
-        entity.writeTo(outstream);
-        if (outstream instanceof ChunkedOutputStream) {
-            ((ChunkedOutputStream) outstream).finish();
-        }
-        outstream.flush();
+        EntityWriter entitywriter = new DefaultEntityWriter();
+        entitywriter.write(
+                response.getEntity(),
+                response.getStatusLine().getHttpVersion(),
+                this.datatransmitter);
     }
         
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityGenerator.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityGenerator.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityGenerator.java Tue Apr 26 14:43:58 2005
@@ -33,7 +33,7 @@
 
 import org.apache.http.HttpException;
 import org.apache.http.HttpMessage;
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 import org.apache.http.io.HttpDataReceiver;
 
 /**
@@ -47,7 +47,7 @@
  */
 public interface EntityGenerator {
 
-    HttpMutableIncomingEntity generate(
+    HttpMutableEntity generate(
             HttpDataReceiver datareceiver,
             HttpMessage message) throws HttpException, IOException;
             

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java?rev=164895&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java Tue Apr 26 14:43:58 2005
@@ -0,0 +1,55 @@
+/*
+ * $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.impl;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpException;
+import org.apache.http.HttpVersion;
+import org.apache.http.io.HttpDataTransmitter;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision: $
+ * 
+ * @since 4.0
+ */
+public interface EntityWriter {
+
+    void write(
+            HttpEntity entity,
+            HttpVersion version,
+            HttpDataTransmitter datatransmitter) throws HttpException, IOException;
+            
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/EntityWriter.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java Tue Apr 26 14:43:58 2005
@@ -29,7 +29,7 @@
 package org.apache.http.impl;
 
 import org.apache.http.Header;
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.StatusLine;
@@ -67,7 +67,7 @@
     }
 
     public void testNoContentLengthResponse() throws Exception {
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         entity.setChunked(false);
         entity.setContentLength(-1);
         StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
@@ -79,7 +79,7 @@
     }
 
     public void testExplicitClose() throws Exception {
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         entity.setChunked(true);
         entity.setContentLength(-1);
         // Use HTTP 1.1
@@ -93,7 +93,7 @@
     }
     
     public void testExplicitKeepAlive() throws Exception {
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         entity.setChunked(false);
         entity.setContentLength(10);
         // Use HTTP 1.0

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultEntityGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultEntityGenerator.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultEntityGenerator.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultEntityGenerator.java Tue Apr 26 14:43:58 2005
@@ -32,7 +32,7 @@
 import java.io.InputStream;
 
 import org.apache.http.Header;
-import org.apache.http.HttpIncomingEntity;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpMutableMessage;
 import org.apache.http.ProtocolException;
 import org.apache.http.io.ChunkedInputStream;
@@ -91,11 +91,11 @@
         message.addHeader(new Header("Transfer-Encoding", "identity, chunked"));
         message.addHeader(new Header("Content-Length", "plain wrong"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertTrue(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ChunkedInputStream);
+        assertTrue(entity.getContent() instanceof ChunkedInputStream);
 
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -103,7 +103,7 @@
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertTrue(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ChunkedInputStream);
+        assertTrue(entity.getContent() instanceof ChunkedInputStream);
     }
 
     public void testEntityWithIdentityTransferEncoding() throws Exception {
@@ -117,11 +117,11 @@
         message.addHeader(new Header("Transfer-Encoding", "identity"));
         message.addHeader(new Header("Content-Length", "plain wrong"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ByteArrayInputStream);
+        assertTrue(entity.getContent() instanceof ByteArrayInputStream);
     }
 
     public void testEntityWithUnsupportedTransferEncoding() throws Exception {
@@ -134,11 +134,11 @@
         message.addHeader(new Header("Transfer-Encoding", "whatever; param=value, chunked"));
         message.addHeader(new Header("Content-Length", "plain wrong"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertTrue(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ChunkedInputStream);
+        assertTrue(entity.getContent() instanceof ChunkedInputStream);
 
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -160,11 +160,11 @@
         message.addHeader(new Header("Transfer-Encoding", "chunked, identity"));
         message.addHeader(new Header("Content-Length", "plain wrong"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertFalse(entity.getInputStream() instanceof ChunkedInputStream);
+        assertFalse(entity.getContent() instanceof ChunkedInputStream);
 
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -185,11 +185,11 @@
         message.addHeader(new Header("Content-Type", "unknown"));
         message.addHeader(new Header("Content-Length", "0"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(0, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ContentLengthInputStream);
+        assertTrue(entity.getContent() instanceof ContentLengthInputStream);
     }
 
     public void testEntityWithMultipleContentLength() throws Exception {
@@ -203,12 +203,12 @@
         message.addHeader(new Header("Content-Length", "0"));
         message.addHeader(new Header("Content-Length", "1"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertNotNull(entity.getInputStream());
-        assertTrue(entity.getInputStream() instanceof ContentLengthInputStream);
+        assertNotNull(entity.getContent());
+        assertTrue(entity.getContent() instanceof ContentLengthInputStream);
         
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -231,12 +231,12 @@
         message.addHeader(new Header("Content-Length", "yyy"));
         message.addHeader(new Header("Content-Length", "xxx"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertNotNull(entity.getInputStream());
-        assertTrue(entity.getInputStream() instanceof ContentLengthInputStream);
+        assertNotNull(entity.getContent());
+        assertTrue(entity.getContent() instanceof ContentLengthInputStream);
         
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -258,13 +258,13 @@
         message.addHeader(new Header("Content-Length", "yyy"));
         message.addHeader(new Header("Content-Length", "xxx"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertNotNull(entity.getInputStream());
-        assertFalse(entity.getInputStream() instanceof ContentLengthInputStream);
-        assertTrue(entity.getInputStream() instanceof HttpDataInputStream);
+        assertNotNull(entity.getContent());
+        assertFalse(entity.getContent() instanceof ContentLengthInputStream);
+        assertTrue(entity.getContent() instanceof HttpDataInputStream);
         
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -285,13 +285,13 @@
         message.addHeader(new Header("Content-Type", "unknown"));
         message.addHeader(new Header("Content-Length", "xxx"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertNotNull(entity.getInputStream());
-        assertFalse(entity.getInputStream() instanceof ContentLengthInputStream);
-        assertTrue(entity.getInputStream() instanceof HttpDataInputStream);
+        assertNotNull(entity.getContent());
+        assertFalse(entity.getContent() instanceof ContentLengthInputStream);
+        assertTrue(entity.getContent() instanceof HttpDataInputStream);
         
         // strict mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, true);
@@ -310,14 +310,14 @@
         // lenient mode 
         message.getParams().setBooleanParameter(HttpProtocolParams.STRICT_TRANSFER_ENCODING, false);
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertNotNull(entity.getInputStream());
-        assertFalse(entity.getInputStream() instanceof ContentLengthInputStream);
-        assertFalse(entity.getInputStream() instanceof ChunkedInputStream);
-        assertTrue(entity.getInputStream() instanceof HttpDataInputStream);
+        assertNotNull(entity.getContent());
+        assertFalse(entity.getContent() instanceof ContentLengthInputStream);
+        assertFalse(entity.getContent() instanceof ChunkedInputStream);
+        assertTrue(entity.getContent() instanceof HttpDataInputStream);
     }
 
     public void testOldIOWrapper() throws Exception {
@@ -326,11 +326,11 @@
         HttpMutableMessage message = new BasicHttpMessage();
         message.addHeader(new Header("Content-Type", "unknown"));
         EntityGenerator entitygen = new DefaultEntityGenerator();
-        HttpIncomingEntity entity = entitygen.generate(datareceiver, message);
+        HttpEntity entity = entitygen.generate(datareceiver, message);
         assertNotNull(entity);
         assertEquals(-1, entity.getContentLength());
         assertFalse(entity.isChunked());
-        assertTrue(entity.getInputStream() instanceof ByteArrayInputStream);
+        assertTrue(entity.getContent() instanceof ByteArrayInputStream);
     }
 
 }

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultResponseConsumedWatcher.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultResponseConsumedWatcher.java?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultResponseConsumedWatcher.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultResponseConsumedWatcher.java Tue Apr 26 14:43:58 2005
@@ -32,7 +32,7 @@
 
 import org.apache.http.Header;
 import org.apache.http.HttpConnection;
-import org.apache.http.HttpMutableIncomingEntity;
+import org.apache.http.HttpMutableEntity;
 import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.StatusLine;
@@ -79,10 +79,10 @@
     public void testConnectionAutoClose() throws Exception {
         byte[] data = new byte[] {'1', '2', '3'};
         HttpConnection conn = new HttpConnectionMockup();
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         entity.setChunked(false);
         entity.setContentLength(data.length);
-        entity.setInputStream(new ByteArrayInputStream(data));
+        entity.setContent(new ByteArrayInputStream(data));
         
         StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
         HttpMutableResponse response = new BasicHttpResponse(statusline);
@@ -92,21 +92,21 @@
         
         // Wrap the entity input stream 
         ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher(conn, response);
-        entity.setInputStream(new AutoCloseInputStream(entity.getInputStream(), watcher));
+        entity.setContent(new AutoCloseInputStream(entity.getContent(), watcher));
         
         assertTrue(conn.isOpen());
         int b;
-        while ((b = entity.getInputStream().read()) != -1) {}
+        while ((b = entity.getContent().read()) != -1) {}
         assertFalse(conn.isOpen());
     }
 
     public void testConnectionKeepAlive() throws Exception {
         byte[] data = new byte[] {'1', '2', '3'};
         HttpConnection conn = new HttpConnectionMockup();
-        HttpMutableIncomingEntity entity = new BasicHttpEntity();
+        HttpMutableEntity entity = new BasicHttpEntity();
         entity.setChunked(false);
         entity.setContentLength(data.length);
-        entity.setInputStream(new ByteArrayInputStream(data));
+        entity.setContent(new ByteArrayInputStream(data));
         
         StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_1, 200, "OK");
         HttpMutableResponse response = new BasicHttpResponse(statusline);
@@ -116,11 +116,11 @@
         
         // Wrap the entity input stream 
         ResponseConsumedWatcher watcher = new DefaultResponseConsumedWatcher(conn, response);
-        entity.setInputStream(new AutoCloseInputStream(entity.getInputStream(), watcher));
+        entity.setContent(new AutoCloseInputStream(entity.getContent(), watcher));
         
         assertTrue(conn.isOpen());
         int b;
-        while ((b = entity.getInputStream().read()) != -1) {}
+        while ((b = entity.getContent().read()) != -1) {}
         assertTrue(conn.isOpen());
     }
 }



Mime
View raw message