hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r231072 - in /jakarta/httpclient/trunk/http-common/src/java/org/apache/http: ./ entity/ impl/ impl/entity/ io/
Date Tue, 09 Aug 2005 18:13:07 GMT
Author: olegk
Date: Tue Aug  9 11:12:51 2005
New Revision: 231072

URL: http://svn.apache.org/viewcvs?rev=231072&view=rev
Log:
Improved server-side support for HttpEntity streaming

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultClientEntityWriter.java
      - copied, changed from r231007, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultServerEntityWriter.java
      - copied, changed from r231007, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
  (with props)
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
  (with props)
Removed:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.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/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/entity/BasicHttpEntity.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ChunkedOutputStream.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=231072&r1=231071&r2=231072&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 Aug
 9 11:12:51 2005
@@ -1,5 +1,5 @@
 /*
- * $Header: $
+ * $HeadURL$
  * $Revision$
  * $Date$
  *
@@ -54,6 +54,21 @@
     
     InputStream getContent() throws IOException;
     
-    void writeTo(OutputStream outstream) throws IOException;
+    /**
+     * Writes the entity content to the output stream either partially or entirely.
+     * This method may either write the entire content in one go, if it is feasible 
+     * to do so, or store the output stream as a local variable and use it internally 
+     * to write the content in parts. If the former case this method MUST return
+     * <tt>true</tt> to indicate that the output stream can be closed. In the
latter
+     * case the output stream MUST be closed once the last content part is written
+     * in order to ensure that content codings that emit a closing chunk are properly
+     * terminated.  
+     * 
+     * @param outstream the output stream to write entity content to
+     * @return <tt>true</tt> if the entire entity content has been written, 
+     *   <tt>false</tt> otherwise.
+     * @throws IOException if an I/O error occurs
+     */
+    boolean 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=231072&r1=231071&r2=231072&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
Tue Aug  9 11:12:51 2005
@@ -91,7 +91,7 @@
         return true;
     }
     
-    public void writeTo(final OutputStream outstream) throws IOException {
+    public boolean writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
@@ -100,6 +100,7 @@
         } else {
             this.source.writeTo(outstream);
         }
+        return true;
     }
     
 }

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=231072&r1=231071&r2=231072&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 Aug  9 11:12:51 2005
@@ -89,12 +89,13 @@
         return new ByteArrayInputStream(this.content);
     }
     
-    public void writeTo(final OutputStream outstream) throws IOException {
+    public boolean writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
         outstream.write(this.content);
         outstream.flush();
+        return true;
     }
 
 }

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=231072&r1=231071&r2=231072&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 Aug  9 11:12:51 2005
@@ -91,7 +91,7 @@
         return this.content;
     }
         
-    public void writeTo(final OutputStream outstream) throws IOException {
+    public boolean writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
@@ -104,6 +104,7 @@
         while ((l = instream.read(tmp)) != -1) {
             outstream.write(tmp, 0, l);
         }
+        return true;
     }
     
 }

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=231072&r1=231071&r2=231072&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 Aug  9 11:12:51 2005
@@ -97,7 +97,7 @@
         return new ByteArrayInputStream(this.content.getBytes(charset));
     }
     
-    public void writeTo(final OutputStream outstream) throws IOException {
+    public boolean writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
@@ -105,6 +105,7 @@
         byte[] content = this.content.getBytes(charset);
         outstream.write(content);
         outstream.flush();
+        return true;
     }
 
 }

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=231072&r1=231071&r2=231072&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 Aug  9 11:12:51 2005
@@ -49,8 +49,8 @@
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.ProtocolException;
 import org.apache.http.StatusLine;
+import org.apache.http.impl.entity.DefaultClientEntityWriter;
 import org.apache.http.impl.entity.DefaultEntityGenerator;
-import org.apache.http.impl.entity.DefaultEntityWriter;
 import org.apache.http.impl.entity.EntityGenerator;
 import org.apache.http.impl.entity.EntityWriter;
 import org.apache.http.io.SocketFactory;
@@ -226,7 +226,7 @@
         if (request.getEntity() == null) {
             return;
         }
-        EntityWriter entitywriter = new DefaultEntityWriter();
+        EntityWriter entitywriter = new DefaultClientEntityWriter();
         entitywriter.write(
                 request.getEntity(),
                 request.getRequestLine().getHttpVersion(),

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=231072&r1=231071&r2=231072&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 Aug  9 11:12:51 2005
@@ -44,7 +44,7 @@
 import org.apache.http.HttpServerConnection;
 import org.apache.http.RequestLine;
 import org.apache.http.impl.entity.DefaultEntityGenerator;
-import org.apache.http.impl.entity.DefaultEntityWriter;
+import org.apache.http.impl.entity.DefaultServerEntityWriter;
 import org.apache.http.impl.entity.EntityGenerator;
 import org.apache.http.impl.entity.EntityWriter;
 import org.apache.http.params.HttpParams;
@@ -180,7 +180,7 @@
         if (response.getEntity() == null) {
             return;
         }
-        EntityWriter entitywriter = new DefaultEntityWriter();
+        EntityWriter entitywriter = new DefaultServerEntityWriter();
         entitywriter.write(
                 response.getEntity(),
                 response.getStatusLine().getHttpVersion(),

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/BasicHttpEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/BasicHttpEntity.java?rev=231072&r1=231071&r2=231072&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/BasicHttpEntity.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/BasicHttpEntity.java
Tue Aug  9 11:12:51 2005
@@ -92,12 +92,12 @@
         this.content = instream; 
     }
     
-    public void writeTo(final OutputStream outstream) throws IOException {
+    public boolean writeTo(final OutputStream outstream) throws IOException {
         if (outstream == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
         if (this.content == null) {
-            return;
+            return true;
         }
         InputStream instream = this.content;
         if (this.length >= 0) {
@@ -108,6 +108,7 @@
         while ((l = instream.read(tmp)) != -1) {
             outstream.write(tmp, 0, l);
         }
+        return true;
     }
     
 }

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultClientEntityWriter.java
(from r231007, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultClientEntityWriter.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultClientEntityWriter.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java&r1=231007&r2=231072&rev=231072&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultClientEntityWriter.java
Tue Aug  9 11:12:51 2005
@@ -51,9 +51,9 @@
  * 
  * @since 4.0
  */
-public class DefaultEntityWriter implements EntityWriter {
+public class DefaultClientEntityWriter implements EntityWriter {
 
-    public DefaultEntityWriter() {
+    public DefaultClientEntityWriter() {
         super();
     }
 
@@ -90,11 +90,9 @@
         if (chunked) {
             outstream = new ChunkedOutputStream(outstream);
         }
-        entity.writeTo(outstream);
-        if (outstream instanceof ChunkedOutputStream) {
-            ((ChunkedOutputStream) outstream).finish();
+        if (entity.writeTo(outstream)) {
+            outstream.close();
         }
-        outstream.flush();
     }
     
 }

Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultServerEntityWriter.java
(from r231007, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultServerEntityWriter.java?p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultServerEntityWriter.java&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java&r1=231007&r2=231072&rev=231072&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultEntityWriter.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/entity/DefaultServerEntityWriter.java
Tue Aug  9 11:12:51 2005
@@ -35,10 +35,11 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
 import org.apache.http.io.ChunkedOutputStream;
+import org.apache.http.io.ContentLengthOutputStream;
 import org.apache.http.io.HttpDataOutputStream;
 import org.apache.http.io.HttpDataTransmitter;
+import org.apache.http.io.IdentityOutputStream;
 import org.apache.http.io.OutputStreamHttpDataTransmitter;
 
 /**
@@ -51,9 +52,9 @@
  * 
  * @since 4.0
  */
-public class DefaultEntityWriter implements EntityWriter {
+public class DefaultServerEntityWriter implements EntityWriter {
 
-    public DefaultEntityWriter() {
+    public DefaultServerEntityWriter() {
         super();
     }
 
@@ -81,20 +82,18 @@
         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) {
+        long len = entity.getContentLength();
+        if (entity.isChunked() && version.greaterEquals(HttpVersion.HTTP_1_1)) {
             outstream = new ChunkedOutputStream(outstream);
+        } else if (len >= 0) {
+            outstream = new ContentLengthOutputStream(outstream, len);
+        } else {
+            outstream = new IdentityOutputStream(outstream); 
         }
-        entity.writeTo(outstream);
-        if (outstream instanceof ChunkedOutputStream) {
-            ((ChunkedOutputStream) outstream).finish();
+        if (entity.writeTo(outstream)) {
+            outstream.close();
         }
-        outstream.flush();
     }
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ChunkedOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ChunkedOutputStream.java?rev=231072&r1=231071&r2=231072&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ChunkedOutputStream.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ChunkedOutputStream.java
Tue Aug  9 11:12:51 2005
@@ -120,6 +120,9 @@
 
     private boolean wroteLastChunk = false;
 
+    /** True if the stream is closed. */
+    private boolean closed = false;
+    
     // ----------------------------------------------------------- Constructors
     /**
      * Wraps a stream and chunks the output.
@@ -207,6 +210,9 @@
 
     // -------------------------------------------- OutputStream Methods
     public void write(int b) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
         cache[cachePosition] = (byte) b;
         cachePosition++;
         if (cachePosition == cache.length) flushCache();
@@ -221,10 +227,13 @@
      * @since 3.0
      */
     public void write(byte b[]) throws IOException {
-        this.write(b, 0, b.length);
+        write(b, 0, b.length);
     }
 
     public void write(byte src[], int off, int len) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
         if (len >= cache.length - cachePosition) {
             flushCacheWithAppend(src, off, len);
         } else {
@@ -246,7 +255,10 @@
      * @throws IOException
      */
     public void close() throws IOException {
-        finish();
-        super.close();
+        if (!this.closed) {
+            this.closed = true;
+            finish();
+            stream.flush();
+        }
     }
 }

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java?rev=231072&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
Tue Aug  9 11:12:51 2005
@@ -0,0 +1,125 @@
+/*
+ * $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.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class ContentLengthOutputStream extends OutputStream {
+    
+    /**
+     * Wrapped output stream that all calls are delegated to.
+     */
+    private final OutputStream wrappedStream;
+
+    /**
+     * The maximum number of bytes that can be written the stream. Subsequent
+     * write operations will be ignored.
+     */
+    private final long contentLength;
+
+    /** Total bytes written */
+    private long total = 0;
+
+    /** True if the stream is closed. */
+    private boolean closed = false;
+
+    /**
+     * Creates a new length limited stream
+     *
+     * @param in The stream to wrap
+     * @param contentLength The maximum number of bytes that can be written to
+     * the stream. Subsequent write operations will be ignored.
+     * 
+     * @since 4.0
+     */
+    public ContentLengthOutputStream(final OutputStream out, long contentLength) {
+        super();
+        if (out == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        if (contentLength < 0) {
+            throw new IllegalArgumentException("Content length may not be negative");
+        }
+        this.wrappedStream = out;
+        this.contentLength = contentLength;
+    }
+
+    /**
+     * <p>Does not close the underlying socket output.</p>
+     * 
+     * @throws IOException If an I/O problem occurs.
+     */
+    public void close() throws IOException {
+        this.closed = true;
+    }
+
+    public void flush() throws IOException {
+        this.wrappedStream.flush();
+    }
+
+    public void write(byte[] b, int off, int len) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
+        if (this.total < this.contentLength) {
+            long max = this.contentLength - this.total;
+            if (len > max) {
+                len = (int) max;
+            }
+            this.wrappedStream.write(b, off, len);
+            this.total += len;
+        }
+    }
+
+    public void write(byte[] b) throws IOException {
+        write(b, 0, b.length);
+    }
+
+    public void write(int b) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
+        if (this.total < this.contentLength) {
+            this.wrappedStream.write(b);
+            this.total++;
+        }
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/ContentLengthOutputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java?rev=231072&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
Tue Aug  9 11:12:51 2005
@@ -0,0 +1,93 @@
+/*
+ * $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.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class IdentityOutputStream extends OutputStream {
+    
+    /**
+     * Wrapped output stream that all calls are delegated to.
+     */
+    private final OutputStream wrappedStream;
+
+    /** True if the stream is closed. */
+    private boolean closed = false;
+
+    public IdentityOutputStream(final OutputStream out) {
+        super();
+        if (out == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        this.wrappedStream = out;
+    }
+
+    /**
+     * <p>Does not close the underlying socket output.</p>
+     * 
+     * @throws IOException If an I/O problem occurs.
+     */
+    public void close() throws IOException {
+        this.closed = true;
+    }
+
+    public void flush() throws IOException {
+        this.wrappedStream.flush();
+    }
+
+    public void write(byte[] b, int off, int len) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
+        this.wrappedStream.write(b, off, len);
+    }
+
+    public void write(byte[] b) throws IOException {
+        write(b, 0, b.length);
+    }
+
+    public void write(int b) throws IOException {
+        if (this.closed) {
+            throw new IOException("Attempted write to closed stream.");
+        }
+        this.wrappedStream.write(b);
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/IdentityOutputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message