hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1377432 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/impl/ main/java/org/apache/http/impl/io/ main/java/org/apache/http/io/ test/java/org/apache/http/impl/ test/java/org/apache/http/impl/io/
Date Sun, 26 Aug 2012 13:10:26 GMT
Author: olegk
Date: Sun Aug 26 13:10:26 2012
New Revision: 1377432

URL: http://svn.apache.org/viewvc?rev=1377432&view=rev
Log:
Rewrite of blocking HTTP connection implementations: deprecated AbstractSessionInputBuffer, SocketInputBuffer in favor of SessionInputBufferImpl; deprecated AbstractSessionOutputBuffer, SocketOutputBuffer in favor of SessionOutputBufferImpl; deprecated EofSensor; added new base class for blocking HTTP connection implementations

Added:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
      - copied, changed from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
      - copied, changed from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java
      - copied, changed from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
Removed:
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSocketInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSocketOutputBuffer.java
Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/EofSensor.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java&r1=1377431&r2=1377432&rev=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java Sun Aug 26 13:10:26 2012
@@ -33,20 +33,24 @@ import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketException;
+import java.net.SocketTimeoutException;
 import java.nio.charset.Charset;
 import java.nio.charset.CodingErrorAction;
 
 import org.apache.http.Consts;
+import org.apache.http.HttpConnection;
+import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpInetConnection;
 import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.impl.io.SocketInputBuffer;
-import org.apache.http.impl.io.SocketOutputBuffer;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.http.impl.io.SessionInputBufferImpl;
+import org.apache.http.impl.io.SessionOutputBufferImpl;
+import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.CharsetUtils;
 
 /**
@@ -57,8 +61,9 @@ import org.apache.http.util.CharsetUtils
  * The following parameters can be used to customize the behavior of this
  * class:
  * <ul>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}</li>
  *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION}</li>
+ *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
  *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
@@ -68,49 +73,25 @@ import org.apache.http.util.CharsetUtils
  * @since 4.0
  */
 @NotThreadSafe
-public class SocketHttpClientConnection
-        extends AbstractHttpClientConnection implements HttpInetConnection {
+public class BHttpConnectionBase implements HttpConnection, HttpInetConnection {
+
+    private final SessionInputBufferImpl inbuffer;
+    private final SessionOutputBufferImpl outbuffer;
+    private final HttpTransportMetricsImpl inTransportMetrics;
+    private final HttpTransportMetricsImpl outTransportMetrics;
+    private final HttpConnectionMetricsImpl connMetrics;
 
     private volatile boolean open;
     private volatile Socket socket = null;
 
-    public SocketHttpClientConnection() {
+    public BHttpConnectionBase(final HttpParams params) {
         super();
-    }
-
-    protected void assertNotOpen() {
-        if (this.open) {
-            throw new IllegalStateException("Connection is already open");
-        }
-    }
-
-    @Override
-    protected void assertOpen() {
-        if (!this.open) {
-            throw new IllegalStateException("Connection is not open");
+        Args.notNull(params, "HTTP parameters");
+        int buffersize = params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
+        if (buffersize <= 0) {
+            buffersize = 4096;
         }
-    }
-
-    /**
-     * Creates an instance of {@link SocketInputBuffer} to be used for
-     * receiving data from the given {@link Socket}.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a custom implementation of {@link SessionInputBuffer} interface.
-     *
-     * @see SocketInputBuffer#SocketInputBuffer(Socket, int, HttpParams)
-     *
-     * @param socket the socket.
-     * @param buffersize the buffer size.
-     * @param params HTTP parameters.
-     * @return session input buffer.
-     * @throws IOException in case of an I/O error.
-     */
-    protected SessionInputBuffer createSessionInputBuffer(
-            final Socket socket,
-            int buffersize,
-            final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
+        Charset charset = CharsetUtils.lookup(
                 (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
         if (charset == null) {
             charset = Consts.ASCII;
@@ -121,75 +102,43 @@ public class SocketHttpClientConnection
                 CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
         CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
                 CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketInputBuffer.create(socket, buffersize, charset, maxLineLen, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+        this.inTransportMetrics = createTransportMetrics();
+        this.outTransportMetrics = createTransportMetrics();
+        this.inbuffer = new SessionInputBufferImpl(
+                this.inTransportMetrics, buffersize, maxLineLen, minChunkLimit,
+                charset, malformedCharAction, unmappableCharAction);
+        this.outbuffer = new SessionOutputBufferImpl(
+                this.outTransportMetrics, buffersize, minChunkLimit,
+                charset, malformedCharAction, unmappableCharAction);
+        this.connMetrics = createConnectionMetrics(
+                this.inTransportMetrics,
+                this.outTransportMetrics);
     }
 
-    /**
-     * Creates an instance of {@link SessionOutputBuffer} to be used for
-     * sending data to the given {@link Socket}.
-     * <p>
-     * This method can be overridden in a super class in order to provide
-     * a custom implementation of {@link SocketOutputBuffer} interface.
-     *
-     * @see SocketOutputBuffer#SocketOutputBuffer(Socket, int, HttpParams)
-     *
-     * @param socket the socket.
-     * @param buffersize the buffer size.
-     * @param params HTTP parameters.
-     * @return session output buffer.
-     * @throws IOException in case of an I/O error.
-     */
-    protected SessionOutputBuffer createSessionOutputBuffer(
-            final Socket socket,
-            int buffersize,
-            final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
-                (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset == null) {
-            charset = Consts.ASCII;
-        }
-        int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketOutputBuffer.create(socket, buffersize, charset, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+    protected void assertNotOpen() {
+        Asserts.check(!this.open, "Connection is already open");
+    }
+
+    protected void assertOpen() {
+        Asserts.check(this.open, "Connection is not open");
     }
 
     /**
      * Binds this connection to the given {@link Socket}. This socket will be
      * used by the connection to send and receive data.
-     * <p>
-     * This method will invoke {@link #createSessionInputBuffer(Socket, int, HttpParams)}
-     * and {@link #createSessionOutputBuffer(Socket, int, HttpParams)} methods
-     * to create session input / output buffers bound to this socket and then
-     * will invoke {@link #init(SessionInputBuffer, SessionOutputBuffer, HttpParams)}
-     * method to pass references to those buffers to the underlying HTTP message
-     * parser and formatter.
-     * <p>
+     * <p/>
      * After this method's execution the connection status will be reported
      * as open and the {@link #isOpen()} will return <code>true</code>.
      *
      * @param socket the socket.
-     * @param params HTTP parameters.
      * @throws IOException in case of an I/O error.
      */
-    protected void bind(
-            final Socket socket,
-            final HttpParams params) throws IOException {
+    protected void bind(final Socket socket) throws IOException {
         Args.notNull(socket, "Socket");
-        Args.notNull(params, "HTTP parameters");
         this.socket = socket;
-
-        int buffersize = params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
-        init(
-                createSessionInputBuffer(socket, buffersize, params),
-                createSessionOutputBuffer(socket, buffersize, params),
-                params);
-
         this.open = true;
+        this.inbuffer.bind(socket.getInputStream());
+        this.outbuffer.bind(socket.getOutputStream());
     }
 
     public boolean isOpen() {
@@ -200,6 +149,16 @@ public class SocketHttpClientConnection
         return this.socket;
     }
 
+    protected HttpTransportMetricsImpl createTransportMetrics() {
+        return new HttpTransportMetricsImpl();
+    }
+
+    protected HttpConnectionMetricsImpl createConnectionMetrics(
+            final HttpTransportMetrics inTransportMetric,
+            final HttpTransportMetrics outTransportMetric) {
+        return new HttpConnectionMetricsImpl(inTransportMetric, outTransportMetric);
+    }
+
     public InetAddress getLocalAddress() {
         if (this.socket != null) {
             return this.socket.getLocalAddress();
@@ -272,7 +231,7 @@ public class SocketHttpClientConnection
         this.open = false;
         Socket sock = this.socket;
         try {
-            doFlush();
+            this.outbuffer.flush();
             try {
                 try {
                     sock.shutdownOutput();
@@ -290,6 +249,35 @@ public class SocketHttpClientConnection
         }
     }
 
+    public boolean isStale() {
+        if (!isOpen()) {
+            return true;
+        }
+        if (this.inbuffer.hasBufferedData()) {
+            return false;
+        }
+        try {
+            int oldtimeout = this.socket.getSoTimeout();
+            try {
+                this.socket.setSoTimeout(1);
+                int i = this.inbuffer.fillBuffer();
+                return i == -1;
+            } catch (SocketTimeoutException ex) {
+                throw ex;
+            } finally {
+                this.socket.setSoTimeout(oldtimeout);
+            }
+        } catch (SocketTimeoutException ex) {
+            return false;
+        } catch (IOException ex) {
+            return true;
+        }
+    }
+
+    public HttpConnectionMetrics getMetrics() {
+        return this.connMetrics;
+    }
+
     private static void formatAddress(final StringBuilder buffer, final SocketAddress socketAddress) {
         if (socketAddress instanceof InetSocketAddress) {
             InetSocketAddress addr = ((InetSocketAddress) socketAddress);

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java Sun Aug 26 13:10:26 2012
@@ -33,10 +33,7 @@ import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketException;
-import java.nio.charset.Charset;
-import java.nio.charset.CodingErrorAction;
 
-import org.apache.http.Consts;
 import org.apache.http.HttpInetConnection;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.impl.io.SocketInputBuffer;
@@ -44,10 +41,8 @@ import org.apache.http.impl.io.SocketOut
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.io.SessionOutputBuffer;
 import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
-import org.apache.http.util.CharsetUtils;
 
 /**
  * Implementation of a client-side HTTP connection that can be bound to an
@@ -110,19 +105,7 @@ public class SocketHttpClientConnection
             final Socket socket,
             int buffersize,
             final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
-                (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset == null) {
-            charset = Consts.ASCII;
-        }
-        int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketInputBuffer.create(socket, buffersize, charset, maxLineLen, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+        return new SocketInputBuffer(socket, buffersize, params);
     }
 
     /**
@@ -144,18 +127,7 @@ public class SocketHttpClientConnection
             final Socket socket,
             int buffersize,
             final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
-                (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset == null) {
-            charset = Consts.ASCII;
-        }
-        int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketOutputBuffer.create(socket, buffersize, charset, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+        return new SocketOutputBuffer(socket, buffersize, params);
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java Sun Aug 26 13:10:26 2012
@@ -33,10 +33,7 @@ import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketException;
-import java.nio.charset.Charset;
-import java.nio.charset.CodingErrorAction;
 
-import org.apache.http.Consts;
 import org.apache.http.HttpInetConnection;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.impl.io.SocketInputBuffer;
@@ -44,10 +41,8 @@ import org.apache.http.impl.io.SocketOut
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.io.SessionOutputBuffer;
 import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
-import org.apache.http.util.CharsetUtils;
 
 /**
  * Implementation of a server-side HTTP connection that can be bound to a
@@ -109,19 +104,7 @@ public class SocketHttpServerConnection 
             final Socket socket,
             int buffersize,
             final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
-                (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset == null) {
-            charset = Consts.ASCII;
-        }
-        int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketInputBuffer.create(socket, buffersize, charset, maxLineLen, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+        return new SocketInputBuffer(socket, buffersize, params);
     }
 
     /**
@@ -143,18 +126,7 @@ public class SocketHttpServerConnection 
             final Socket socket,
             int buffersize,
             final HttpParams params) throws IOException {
-        Charset charset = CharsetUtils.get(
-                (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset == null) {
-            charset = Consts.ASCII;
-        }
-        int minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CodingErrorAction malformedCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        CodingErrorAction unmappableCharAction = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        return SocketOutputBuffer.create(socket, buffersize, charset, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
+        return new SocketOutputBuffer(socket, buffersize, params);
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java Sun Aug 26 13:10:26 2012
@@ -59,11 +59,13 @@ import org.apache.http.util.CharArrayBuf
  * by the HTTP specification.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) use {@link SessionInputBufferImpl}
  */
 @NotThreadSafe
+@Deprecated
 public abstract class AbstractSessionInputBuffer implements SessionInputBuffer, BufferInfo {
 
-    // TODO: make final
     private InputStream instream;
     private byte[] buffer;
     private ByteArrayBuffer linebuffer;
@@ -80,58 +82,6 @@ public abstract class AbstractSessionInp
     private CharsetDecoder decoder;
     private CharBuffer cbuf;
 
-    /**
-     * Creates new instance of AbstractSessionInputBuffer.
-     *
-     * @param instream input stream.
-     * @param buffersize buffer size. Must be a positive number.
-     * @param charset charset to be used for decoding HTTP protocol elements.
-     *   If <code>null</code> US-ASCII will be used.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
-     * @param minChunkLimit size limit below which data chunks should be buffered in memory
-     *   in order to minimize native method invocations on the underlying network socket.
-     *   The optimal value of this parameter can be platform specific and defines a trade-off
-     *   between performance of memory copy operations and that of native method invocation.
-     *   If negative default chunk limited will be used.
-     * @param malformedCharAction action to perform upon receiving a malformed input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
-     * @param unmappableCharAction action to perform upon receiving an unmappable input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
-     */
-    protected AbstractSessionInputBuffer(
-            final InputStream instream,
-            int buffersize,
-            final Charset charset,
-            int maxLineLen,
-            int minChunkLimit,
-            final CodingErrorAction malformedCharAction,
-            final CodingErrorAction unmappableCharAction) {
-        Args.notNull(instream, "Input stream");
-        Args.positive(buffersize, "Buffer size");
-        this.instream = instream;
-        this.buffer = new byte[buffersize];
-        this.bufferpos = 0;
-        this.bufferlen = 0;
-        this.linebuffer = new ByteArrayBuffer(buffersize);
-        this.charset = charset != null ? charset : Consts.ASCII;
-        this.ascii = this.charset.equals(Consts.ASCII);
-        this.decoder = null;
-        this.maxLineLen = maxLineLen >= 0 ? maxLineLen : -1;
-        this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
-        this.metrics = createTransportMetrics();
-        this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction :
-            CodingErrorAction.REPORT;
-        this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction :
-            CodingErrorAction.REPORT;
-    }
-
-    /**
-     * @deprecated (4.3)
-     */
-    @Deprecated
     protected AbstractSessionInputBuffer() {
     }
 
@@ -141,11 +91,7 @@ public abstract class AbstractSessionInp
      * @param instream the source input stream.
      * @param buffersize the size of the internal buffer.
      * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use constructor
-     *     {@link AbstractSessionInputBuffer#AbstractSessionInputBuffer(InputStream, int, HttpParams)}
      */
-    @Deprecated
     protected void init(final InputStream instream, int buffersize, final HttpParams params) {
         Args.notNull(instream, "Input stream");
         Args.notNegative(buffersize, "Buffer size");

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java Sun Aug 26 13:10:26 2012
@@ -58,13 +58,15 @@ import org.apache.http.util.CharArrayBuf
  * of this class use CR-LF as a line delimiter.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) use {@link SessionOutputBufferImpl}
  */
 @NotThreadSafe
+@Deprecated
 public abstract class AbstractSessionOutputBuffer implements SessionOutputBuffer, BufferInfo {
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
 
-    // TODO: make final
     private OutputStream outstream;
     private ByteArrayBuffer buffer;
     private Charset charset;
@@ -77,25 +79,6 @@ public abstract class AbstractSessionOut
     private CharsetEncoder encoder;
     private ByteBuffer bbuf;
 
-    /**
-     * Creates new instance of AbstractSessionOutputBuffer.
-     *
-     * @param outstream output stream.
-     * @param buffersize buffer size. Must be a positive number.
-     * @param charset charset to be used for encoding HTTP protocol elements.
-     *   If <code>null</code> US-ASCII will be used.
-     * @param minChunkLimit size limit below which data chunks should be buffered in memory
-     *   in order to minimize native method invocations on the underlying network socket.
-     *   The optimal value of this parameter can be platform specific and defines a trade-off
-     *   between performance of memory copy operations and that of native method invocation.
-     *   If negative default chunk limited will be used.
-     * @param malformedCharAction action to perform upon receiving a malformed input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
-     * @param unmappableCharAction action to perform upon receiving an unmappable input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
-     */
     protected AbstractSessionOutputBuffer(
             final OutputStream outstream,
             int buffersize,
@@ -119,24 +102,9 @@ public abstract class AbstractSessionOut
             CodingErrorAction.REPORT;
     }
 
-    /**
-     * @deprecated (4.3)
-     */
-    @Deprecated
     protected AbstractSessionOutputBuffer() {
     }
 
-    /**
-     * Initializes this session output buffer.
-     *
-     * @param outstream the destination output stream.
-     * @param buffersize the size of the internal buffer.
-     * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use constructor
-     *   {@link AbstractSessionOutputBuffer#AbstractSessionOutputBuffer(OutputStream, int, HttpParams)}
-     */
-    @Deprecated
     protected void init(final OutputStream outstream, int buffersize, final HttpParams params) {
         Args.notNull(outstream, "Input stream");
         Args.notNegative(buffersize, "Buffer size");

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java&r1=1377431&r2=1377432&rev=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java Sun Aug 26 13:10:26 2012
@@ -41,11 +41,9 @@ import org.apache.http.annotation.NotThr
 import org.apache.http.io.BufferInfo;
 import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.ByteArrayBuffer;
 import org.apache.http.util.CharArrayBuffer;
 
@@ -53,40 +51,37 @@ import org.apache.http.util.CharArrayBuf
  * Abstract base class for session input buffers that stream data from
  * an arbitrary {@link InputStream}. This class buffers input data in
  * an internal byte array for optimal input performance.
- * <p>
+ * <p/>
  * {@link #readLine(CharArrayBuffer)} and {@link #readLine()} methods of this
  * class treat a lone LF as valid line delimiters in addition to CR-LF required
  * by the HTTP specification.
  *
- * @since 4.0
+ * @since 4.3
  */
 @NotThreadSafe
-public abstract class AbstractSessionInputBuffer implements SessionInputBuffer, BufferInfo {
+public class SessionInputBufferImpl implements SessionInputBuffer, BufferInfo {
 
-    // TODO: make final
-    private InputStream instream;
-    private byte[] buffer;
-    private ByteArrayBuffer linebuffer;
-    private Charset charset;
-    private boolean ascii;
-    private int maxLineLen;
-    private int minChunkLimit;
-    private HttpTransportMetricsImpl metrics;
-    private CodingErrorAction onMalformedCharAction;
-    private CodingErrorAction onUnmappableCharAction;
+    private final HttpTransportMetricsImpl metrics;
+    private final byte[] buffer;
+    private final ByteArrayBuffer linebuffer;
+    private final Charset charset;
+    private final boolean ascii;
+    private final int maxLineLen;
+    private final int minChunkLimit;
+    private final CodingErrorAction onMalformedCharAction;
+    private final CodingErrorAction onUnmappableCharAction;
 
+    private InputStream instream;
     private int bufferpos;
     private int bufferlen;
     private CharsetDecoder decoder;
     private CharBuffer cbuf;
 
     /**
-     * Creates new instance of AbstractSessionInputBuffer.
+     * Creates new instance of SessionInputBufferImpl.
      *
-     * @param instream input stream.
+     * @param metrics HTTP transport metrics.
      * @param buffersize buffer size. Must be a positive number.
-     * @param charset charset to be used for decoding HTTP protocol elements.
-     *   If <code>null</code> US-ASCII will be used.
      * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
      *   this limit will cause an I/O error. A negative value will disable the check.
      * @param minChunkLimit size limit below which data chunks should be buffered in memory
@@ -94,111 +89,61 @@ public abstract class AbstractSessionInp
      *   The optimal value of this parameter can be platform specific and defines a trade-off
      *   between performance of memory copy operations and that of native method invocation.
      *   If negative default chunk limited will be used.
+     * @param charset charset to be used for decoding HTTP protocol elements.
+     *   If <code>null</code> US-ASCII will be used.
      * @param malformedCharAction action to perform upon receiving a malformed input.
      *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
      * @param unmappableCharAction action to perform upon receiving an unmappable input.
      *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
      */
-    protected AbstractSessionInputBuffer(
-            final InputStream instream,
+    public SessionInputBufferImpl(
+            final HttpTransportMetricsImpl metrics,
             int buffersize,
-            final Charset charset,
             int maxLineLen,
             int minChunkLimit,
+            final Charset charset,
             final CodingErrorAction malformedCharAction,
             final CodingErrorAction unmappableCharAction) {
-        Args.notNull(instream, "Input stream");
         Args.positive(buffersize, "Buffer size");
-        this.instream = instream;
+        Args.notNull(metrics, "HTTP transport metrcis");
+        this.metrics = metrics;
         this.buffer = new byte[buffersize];
         this.bufferpos = 0;
         this.bufferlen = 0;
+        this.maxLineLen = maxLineLen >= 0 ? maxLineLen : -1;
+        this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
         this.linebuffer = new ByteArrayBuffer(buffersize);
         this.charset = charset != null ? charset : Consts.ASCII;
         this.ascii = this.charset.equals(Consts.ASCII);
         this.decoder = null;
-        this.maxLineLen = maxLineLen >= 0 ? maxLineLen : -1;
-        this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
-        this.metrics = createTransportMetrics();
         this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction :
             CodingErrorAction.REPORT;
         this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction :
             CodingErrorAction.REPORT;
     }
 
-    /**
-     * @deprecated (4.3)
-     */
-    @Deprecated
-    protected AbstractSessionInputBuffer() {
-    }
-
-    /**
-     * Initializes this session input buffer.
-     *
-     * @param instream the source input stream.
-     * @param buffersize the size of the internal buffer.
-     * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use constructor
-     *     {@link AbstractSessionInputBuffer#AbstractSessionInputBuffer(InputStream, int, HttpParams)}
-     */
-    @Deprecated
-    protected void init(final InputStream instream, int buffersize, final HttpParams params) {
-        Args.notNull(instream, "Input stream");
-        Args.notNegative(buffersize, "Buffer size");
-        Args.notNull(params, "HTTP parameters");
+    public void bind(final InputStream instream) {
         this.instream = instream;
-        this.buffer = new byte[buffersize];
-        this.bufferpos = 0;
-        this.bufferlen = 0;
-        this.linebuffer = new ByteArrayBuffer(buffersize);
-        String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
-        this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
-        this.ascii = this.charset.equals(Consts.ASCII);
-        this.decoder = null;
-        this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
-        this.metrics = createTransportMetrics();
-        CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT;
-        CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT;
-    }
-
-    /**
-     * @since 4.1
-     */
-    protected HttpTransportMetricsImpl createTransportMetrics() {
-        return new HttpTransportMetricsImpl();
     }
 
-    /**
-     * @since 4.1
-     */
     public int capacity() {
         return this.buffer.length;
     }
 
-    /**
-     * @since 4.1
-     */
     public int length() {
         return this.bufferlen - this.bufferpos;
     }
 
-    /**
-     * @since 4.1
-     */
     public int available() {
         return capacity() - length();
     }
 
-    protected int fillBuffer() throws IOException {
+    private int streamRead(final byte[] b, int off, int len) throws IOException {
+        Asserts.notNull(this.instream, "Input stream");
+        return this.instream.read(b, off, len);
+    }
+
+    public int fillBuffer() throws IOException {
         // compact the buffer if necessary
         if (this.bufferpos > 0) {
             int len = this.bufferlen - this.bufferpos;
@@ -211,7 +156,7 @@ public abstract class AbstractSessionInp
         int l;
         int off = this.bufferlen;
         int len = this.buffer.length - off;
-        l = this.instream.read(this.buffer, off, len);
+        l = streamRead(this.buffer, off, len);
         if (l == -1) {
             return -1;
         } else {
@@ -221,7 +166,7 @@ public abstract class AbstractSessionInp
         }
     }
 
-    protected boolean hasBufferedData() {
+    public boolean hasBufferedData() {
         return this.bufferpos < this.bufferlen;
     }
 
@@ -249,7 +194,7 @@ public abstract class AbstractSessionInp
         // If the remaining capacity is big enough, read directly from the
         // underlying input stream bypassing the buffer.
         if (len > this.minChunkLimit) {
-            int read = this.instream.read(b, off, len);
+            int read = streamRead(b, off, len);
             if (read > 0) {
                 this.metrics.incrementBytesTransferred(read);
             }
@@ -448,6 +393,10 @@ public abstract class AbstractSessionInp
         }
     }
 
+    public boolean isDataAvailable(int timeout) throws IOException {
+        return hasBufferedData();
+    }
+
     public HttpTransportMetrics getMetrics() {
         return this.metrics;
     }

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java (from r1377431, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java&r1=1377431&r2=1377432&rev=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java Sun Aug 26 13:10:26 2012
@@ -41,11 +41,9 @@ import org.apache.http.annotation.NotThr
 import org.apache.http.io.BufferInfo;
 import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.ByteArrayBuffer;
 import org.apache.http.util.CharArrayBuffer;
 
@@ -57,30 +55,29 @@ import org.apache.http.util.CharArrayBuf
  * {@link #writeLine(CharArrayBuffer)} and {@link #writeLine(String)} methods
  * of this class use CR-LF as a line delimiter.
  *
- * @since 4.0
+ * @since 4.3
  */
 @NotThreadSafe
-public abstract class AbstractSessionOutputBuffer implements SessionOutputBuffer, BufferInfo {
+public class SessionOutputBufferImpl implements SessionOutputBuffer, BufferInfo {
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
 
-    // TODO: make final
-    private OutputStream outstream;
-    private ByteArrayBuffer buffer;
-    private Charset charset;
-    private boolean ascii;
-    private int minChunkLimit;
-    private HttpTransportMetricsImpl metrics;
-    private CodingErrorAction onMalformedCharAction;
-    private CodingErrorAction onUnmappableCharAction;
+    private final HttpTransportMetricsImpl metrics;
+    private final ByteArrayBuffer buffer;
+    private final Charset charset;
+    private final boolean ascii;
+    private final int minChunkLimit;
+    private final CodingErrorAction onMalformedCharAction;
+    private final CodingErrorAction onUnmappableCharAction;
 
+    private OutputStream outstream;
     private CharsetEncoder encoder;
     private ByteBuffer bbuf;
 
     /**
-     * Creates new instance of AbstractSessionOutputBuffer.
+     * Creates new instance of SessionOutputBufferImpl.
      *
-     * @param outstream output stream.
+     * @param metrics HTTP transport metrics.
      * @param buffersize buffer size. Must be a positive number.
      * @param charset charset to be used for encoding HTTP protocol elements.
      *   If <code>null</code> US-ASCII will be used.
@@ -93,102 +90,59 @@ public abstract class AbstractSessionOut
      *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
      * @param unmappableCharAction action to perform upon receiving an unmappable input.
      *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
      */
-    protected AbstractSessionOutputBuffer(
-            final OutputStream outstream,
+    public SessionOutputBufferImpl(
+            final HttpTransportMetricsImpl metrics,
             int buffersize,
-            final Charset charset,
             int minChunkLimit,
+            final Charset charset,
             final CodingErrorAction malformedCharAction,
             final CodingErrorAction unmappableCharAction) {
         super();
-        Args.notNull(outstream, "Input stream");
-        Args.notNegative(buffersize, "Buffer size");
-        this.outstream = outstream;
+        Args.positive(buffersize, "Buffer size");
+        Args.notNull(metrics, "HTTP transport metrcis");
+        this.metrics = metrics;
         this.buffer = new ByteArrayBuffer(buffersize);
         this.charset = charset != null ? charset : Consts.ASCII;
         this.ascii = this.charset.equals(Consts.ASCII);
         this.encoder = null;
         this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
-        this.metrics = createTransportMetrics();
         this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction :
             CodingErrorAction.REPORT;
         this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction :
             CodingErrorAction.REPORT;
     }
 
-    /**
-     * @deprecated (4.3)
-     */
-    @Deprecated
-    protected AbstractSessionOutputBuffer() {
-    }
-
-    /**
-     * Initializes this session output buffer.
-     *
-     * @param outstream the destination output stream.
-     * @param buffersize the size of the internal buffer.
-     * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use constructor
-     *   {@link AbstractSessionOutputBuffer#AbstractSessionOutputBuffer(OutputStream, int, HttpParams)}
-     */
-    @Deprecated
-    protected void init(final OutputStream outstream, int buffersize, final HttpParams params) {
-        Args.notNull(outstream, "Input stream");
-        Args.notNegative(buffersize, "Buffer size");
-        Args.notNull(params, "HTTP parameters");
+    public void bind(final OutputStream outstream) {
         this.outstream = outstream;
-        this.buffer = new ByteArrayBuffer(buffersize);
-        String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
-        this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
-        this.ascii = this.charset.equals(Consts.ASCII);
-        this.encoder = null;
-        this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
-        this.metrics = createTransportMetrics();
-        CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-        this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT;
-        CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
-                CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-        this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT;
     }
 
-    /**
-     * @since 4.1
-     */
-    protected HttpTransportMetricsImpl createTransportMetrics() {
-        return new HttpTransportMetricsImpl();
-    }
-
-    /**
-     * @since 4.1
-     */
     public int capacity() {
         return this.buffer.capacity();
     }
 
-    /**
-     * @since 4.1
-     */
     public int length() {
         return this.buffer.length();
     }
 
-    /**
-     * @since 4.1
-     */
     public int available() {
         return capacity() - length();
     }
 
-    protected void flushBuffer() throws IOException {
+    private void streamWrite(final byte[] b, int off, int len) throws IOException {
+        Asserts.notNull(outstream, "Output stream");
+        this.outstream.write(b, off, len);
+    }
+
+    private void flushStream() throws IOException {
+        Asserts.notNull(outstream, "Output stream");
+        this.outstream.flush();
+    }
+
+    private void flushBuffer() throws IOException {
         int len = this.buffer.length();
         if (len > 0) {
-            this.outstream.write(this.buffer.buffer(), 0, len);
+            streamWrite(this.buffer.buffer(), 0, len);
             this.buffer.clear();
             this.metrics.incrementBytesTransferred(len);
         }
@@ -196,7 +150,7 @@ public abstract class AbstractSessionOut
 
     public void flush() throws IOException {
         flushBuffer();
-        this.outstream.flush();
+        flushStream();
     }
 
     public void write(final byte[] b, int off, int len) throws IOException {
@@ -210,7 +164,7 @@ public abstract class AbstractSessionOut
             // flush the buffer
             flushBuffer();
             // write directly to the out stream
-            this.outstream.write(b, off, len);
+            streamWrite(b, off, len);
             this.metrics.incrementBytesTransferred(len);
         } else {
             // Do not let the buffer grow unnecessarily

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketInputBuffer.java Sun Aug 26 13:10:26 2012
@@ -30,8 +30,6 @@ package org.apache.http.impl.io;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
-import java.nio.charset.Charset;
-import java.nio.charset.CodingErrorAction;
 
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.io.EofSensor;
@@ -43,8 +41,11 @@ import org.apache.http.util.Args;
  * {@link SessionInputBuffer} implementation bound to a {@link Socket}.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) use {@link SessionInputBufferImpl}
  */
 @NotThreadSafe
+@Deprecated
 public class SocketInputBuffer extends AbstractSessionInputBuffer implements EofSensor {
 
     private final Socket socket;
@@ -60,10 +61,7 @@ public class SocketInputBuffer extends A
      *   {@link Socket#getReceiveBufferSize()}. If resultant number is less
      *   than <code>1024</code> it is set to <code>1024</code>.
      * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use {@link SocketInputBuffer#create(Socket, int, Charset, int, int, CodingErrorAction, CodingErrorAction)}
      */
-    @Deprecated
     public SocketInputBuffer(
             final Socket socket,
             int buffersize,
@@ -81,78 +79,6 @@ public class SocketInputBuffer extends A
         init(socket.getInputStream(), buffersize, params);
     }
 
-    SocketInputBuffer(
-            final Socket socket,
-            int buffersize,
-            final Charset charset,
-            int maxLineLen,
-            int minChunkLimit,
-            final CodingErrorAction malformedCharAction,
-            final CodingErrorAction unmappableCharAction) throws IOException {
-        super(socket.getInputStream(), buffersize, charset, maxLineLen, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
-        this.socket = socket;
-        this.eof = false;
-    }
-
-    /**
-     * Creates SocketInputBuffer instance.
-     *
-     * @param socket socket
-     * @param buffersize buffer size. If this number is negative it is set to the value of
-     *   {@link Socket#getReceiveBufferSize()}. If resultant number is less than
-     *   <code>1024</code> it is set to <code>1024</code>.
-     * @param charset charset to be used for decoding HTTP protocol elements.
-     *   If <code>null</code> US-ASCII will be used.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
-     * @param minChunkLimit size limit below which data chunks should be buffered in memory
-     *   in order to minimize native method invocations on the underlying network socket.
-     *   The optimal value of this parameter can be platform specific and defines a trade-off
-     *   between performance of memory copy operations and that of native method invocation.
-     *   If negative default chunk limited will be used.
-     * @param malformedCharAction action to perform upon receiving a malformed input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
-     * @param unmappableCharAction action to perform upon receiving an unmappable input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
-     */
-    public static SocketInputBuffer create(
-            final Socket socket,
-            int buffersize,
-            final Charset charset,
-            int maxLineLen,
-            int minChunkLimit,
-            final CodingErrorAction malformedCharAction,
-            final CodingErrorAction unmappableCharAction) throws IOException {
-        Args.notNull(socket, "Socket");
-        if (buffersize < 0) {
-            buffersize = socket.getReceiveBufferSize();
-        }
-        if (buffersize < 1024) {
-            buffersize = 1024;
-        }
-        return new SocketInputBuffer(socket, buffersize, charset, maxLineLen, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
-    }
-
-    /**
-     * Creates SocketInputBuffer instance.
-     *
-     * @param socket socket
-     * @param buffersize buffer size. If this number is negative it is set to the value of
-     *   {@link Socket#getReceiveBufferSize()}. If resultant number is less than
-     *   <code>1024</code> it is set to <code>1024</code>.
-     *
-     * @since 4.3
-     */
-    public static SocketInputBuffer create(
-            final Socket socket,
-            int buffersize) throws IOException {
-        return create(socket, buffersize, null, -1, -1, null, null);
-    }
-
     @Override
     protected int fillBuffer() throws IOException {
         int i = super.fillBuffer();

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketOutputBuffer.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SocketOutputBuffer.java Sun Aug 26 13:10:26 2012
@@ -29,8 +29,6 @@ package org.apache.http.impl.io;
 
 import java.io.IOException;
 import java.net.Socket;
-import java.nio.charset.Charset;
-import java.nio.charset.CodingErrorAction;
 
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.io.SessionOutputBuffer;
@@ -41,8 +39,11 @@ import org.apache.http.util.Args;
  * {@link SessionOutputBuffer} implementation bound to a {@link Socket}.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) use {@link SessionOutputBufferImpl}
  */
 @NotThreadSafe
+@Deprecated
 public class SocketOutputBuffer extends AbstractSessionOutputBuffer {
 
     /**
@@ -54,10 +55,7 @@ public class SocketOutputBuffer extends 
      *   {@link Socket#getSendBufferSize()}. If resultant number is less
      *   than <code>1024</code> it is set to <code>1024</code>.
      * @param params HTTP parameters.
-     *
-     * @deprecated (4.3) use {@link SocketOutputBuffer#create(Socket, int, Charset, int, CodingErrorAction, CodingErrorAction)}
      */
-    @Deprecated
     public SocketOutputBuffer(
             final Socket socket,
             int buffersize,
@@ -73,70 +71,4 @@ public class SocketOutputBuffer extends 
         init(socket.getOutputStream(), buffersize, params);
     }
 
-    SocketOutputBuffer(
-            final Socket socket,
-            int buffersize,
-            final Charset charset,
-            int minChunkLimit,
-            final CodingErrorAction malformedCharAction,
-            final CodingErrorAction unmappableCharAction) throws IOException {
-        super(socket.getOutputStream(), buffersize, charset, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
-    }
-
-    /**
-     * Creates SocketOutputBuffer instance.
-     *
-     * @param socket socket
-     * @param buffersize buffer size. If this number is negative it is set to the value of
-     *   {@link Socket#getSendBufferSize()}. If resultant number is less than
-     *   <code>1024</code> it is set to <code>1024</code>.
-     * @param charset charset to be used for decoding HTTP protocol elements.
-     *   If <code>null</code> US-ASCII will be used.
-     * @param minChunkLimit size limit below which data chunks should be buffered in memory
-     *   in order to minimize native method invocations on the underlying network socket.
-     *   The optimal value of this parameter can be platform specific and defines a trade-off
-     *   between performance of memory copy operations and that of native method invocation.
-     *   If negative default chunk limited will be used.
-     * @param malformedCharAction action to perform upon receiving a malformed input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT} will be used.
-     * @param unmappableCharAction action to perform upon receiving an unmappable input.
-     *   If <code>null</code> {@link CodingErrorAction#REPORT}  will be used.
-     *
-     * @since 4.3
-     */
-    public static SocketOutputBuffer create(
-            final Socket socket,
-            int buffersize,
-            final Charset charset,
-            int minChunkLimit,
-            final CodingErrorAction malformedCharAction,
-            final CodingErrorAction unmappableCharAction) throws IOException {
-        Args.notNull(socket, "Socket");
-        if (buffersize < 0) {
-            buffersize = socket.getSendBufferSize();
-        }
-        if (buffersize < 1024) {
-            buffersize = 1024;
-        }
-        return new SocketOutputBuffer(socket, buffersize, charset, minChunkLimit,
-                malformedCharAction, unmappableCharAction);
-    }
-
-    /**
-     * Creates SocketOutputBuffer instance.
-     *
-     * @param socket socket
-     * @param buffersize buffer size. If this number is negative it is set to the value of
-     *   {@link Socket#getSendBufferSize()}. If resultant number is less than
-     *   <code>1024</code> it is set to <code>1024</code>.
-     *
-     * @since 4.3
-     */
-    public static SocketOutputBuffer create(
-            final Socket socket,
-            int buffersize) throws IOException {
-        return create(socket, buffersize, null, -1, null, null);
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/EofSensor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/EofSensor.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/EofSensor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/EofSensor.java Sun Aug 26 13:10:26 2012
@@ -31,7 +31,10 @@ package org.apache.http.io;
  * EOF sensor.
  *
  * @since 4.0
+ * 
+ * @deprecated (4.3) no longer used.
  */
+@Deprecated
 public interface EofSensor {
 
     boolean isEof();

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/SessionInputBuffer.java Sun Aug 26 13:10:26 2012
@@ -135,7 +135,11 @@ public interface SessionInputBuffer {
      * @return <code>true</code> if some data is available in the session
      *   buffer or <code>false</code> otherwise.
      * @exception  IOException  if an I/O error occurs.
+     * 
+     * @deprecated (4.3) do not use. This function should be provided at the 
+     *   connection level
      */
+    @Deprecated
     boolean isDataAvailable(int timeout) throws IOException;
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java Sun Aug 26 13:10:26 2012
@@ -35,31 +35,33 @@ import java.nio.charset.Charset;
 import java.nio.charset.CodingErrorAction;
 
 import org.apache.http.Consts;
-import org.apache.http.impl.io.AbstractSessionInputBuffer;
+import org.apache.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.http.impl.io.SessionInputBufferImpl;
 
 /**
  * {@link org.apache.http.io.SessionInputBuffer} mockup implementation.
  */
-public class SessionInputBufferMock extends AbstractSessionInputBuffer {
+public class SessionInputBufferMock extends SessionInputBufferImpl {
 
     public static final int BUFFER_SIZE = 16;
 
     public SessionInputBufferMock(
             final InputStream instream, 
             int buffersize, 
-            final Charset charset,
             int maxLineLen,
             int minChunkLimit,
+            final Charset charset,
             final CodingErrorAction malformedInputAction,
             final CodingErrorAction unmappableInputAction) {
-        super(instream, buffersize, charset, maxLineLen, minChunkLimit, 
-                malformedInputAction, unmappableInputAction);
+        super(new HttpTransportMetricsImpl(), buffersize, maxLineLen, minChunkLimit, 
+                charset, malformedInputAction, unmappableInputAction);
+        bind(instream);
     }
 
     public SessionInputBufferMock(
             final InputStream instream,
             int buffersize) {
-        this(instream, buffersize, null, -1, -1, null, null);
+        this(instream, buffersize, -1, -1, null, null, null);
     }
 
     public SessionInputBufferMock(
@@ -70,15 +72,15 @@ public class SessionInputBufferMock exte
             int minChunkLimit,
             final CodingErrorAction malformedInputAction,
             final CodingErrorAction unmappableInputAction) {
-        this(new ByteArrayInputStream(bytes), buffersize, charset, maxLineLen, minChunkLimit, 
-                malformedInputAction, unmappableInputAction);
+        this(new ByteArrayInputStream(bytes), buffersize, maxLineLen, minChunkLimit, 
+                charset, malformedInputAction, unmappableInputAction);
     }
 
     public SessionInputBufferMock(
             final byte[] bytes,
             int buffersize,
             int maxLineLen) {
-        this(new ByteArrayInputStream(bytes), buffersize, Consts.ASCII, maxLineLen, -1, null, null);
+        this(new ByteArrayInputStream(bytes), buffersize, maxLineLen, -1, Consts.ASCII, null, null);
     }
 
     public SessionInputBufferMock(

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java?rev=1377432&r1=1377431&r2=1377432&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java Sun Aug 26 13:10:26 2012
@@ -31,13 +31,14 @@ import java.io.ByteArrayOutputStream;
 import java.nio.charset.Charset;
 import java.nio.charset.CodingErrorAction;
 
-import org.apache.http.impl.io.AbstractSessionOutputBuffer;
+import org.apache.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.http.impl.io.SessionOutputBufferImpl;
 
 /**
  * {@link org.apache.http.io.SessionOutputBuffer} mockup implementation.
  *
  */
-public class SessionOutputBufferMock extends AbstractSessionOutputBuffer {
+public class SessionOutputBufferMock extends SessionOutputBufferImpl {
 
     public static final int BUFFER_SIZE = 16;
 
@@ -46,36 +47,37 @@ public class SessionOutputBufferMock ext
     public SessionOutputBufferMock(
             final ByteArrayOutputStream buffer, 
             int buffersize, 
-            final Charset charset,
             int minChunkLimit,
+            final Charset charset,
             final CodingErrorAction malformedInputAction,
             final CodingErrorAction unmappableInputAction) {
-        super(buffer, buffersize, charset, 
-                minChunkLimit, malformedInputAction, unmappableInputAction);
+        super(new HttpTransportMetricsImpl(), buffersize, minChunkLimit, 
+                charset, malformedInputAction, unmappableInputAction);
+        bind(buffer);
         this.buffer = buffer;
     }
 
     public SessionOutputBufferMock(
             final ByteArrayOutputStream buffer,
             int buffersize) {
-        this(buffer, buffersize, null, -1, null, null);
+        this(buffer, buffersize, -1, null, null, null);
     }
 
     public SessionOutputBufferMock(
             final Charset charset,
             final CodingErrorAction malformedInputAction,
             final CodingErrorAction unmappableInputAction) {
-        this(new ByteArrayOutputStream(), BUFFER_SIZE, charset, -1, 
-                malformedInputAction, unmappableInputAction);
+        this(new ByteArrayOutputStream(), BUFFER_SIZE, -1, 
+                charset, malformedInputAction, unmappableInputAction);
     }
     
     public SessionOutputBufferMock(
             final Charset charset) {
-        this(new ByteArrayOutputStream(), BUFFER_SIZE, charset, -1, null, null);
+        this(new ByteArrayOutputStream(), BUFFER_SIZE, -1, charset, null, null);
     }
 
     public SessionOutputBufferMock(final ByteArrayOutputStream buffer) {
-        this(buffer, BUFFER_SIZE, null, -1, null, null);
+        this(buffer, BUFFER_SIZE, -1, null, null, null);
     }
 
     public SessionOutputBufferMock() {



Mime
View raw message