hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1727970 [1/4] - in /httpcomponents/httpcore/trunk: httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/ httpcore5/src/main/java/org/apache/hc/core5/http/impl/ httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ httpcore5/sr...
Date Mon, 01 Feb 2016 16:56:00 GMT
Author: olegk
Date: Mon Feb  1 16:55:59 2016
New Revision: 1727970

URL: http://svn.apache.org/viewvc?rev=1727970&view=rev
Log:
Cleanup of blocking session input / output buffering code

Added:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java   (contents, props changed)
      - copied, changed from r1727859, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpTransportMetricsImpl.java
Removed:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpTransportMetricsImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/SessionInputBufferMock.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferMock.java
Modified:
    httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageParser.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageWriter.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedOutputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthOutputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityInputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityOutputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpMessageParser.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpMessageWriter.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestChunkCoding.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestContentLengthInputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestContentLengthOutputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestIdentityInputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestIdentityOutputStream.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestMessageParser.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestRequestParser.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestResponseParser.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestSessionInOutBuffers.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/ContentEncoderMock.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestBuffers.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedDecoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java
    httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/integration/TestTruncatedChunks.java

Modified: httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/BenchmarkConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/BenchmarkConnection.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/BenchmarkConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/BenchmarkConnection.java Mon Feb  1 16:55:59 2016
@@ -46,15 +46,18 @@ class BenchmarkConnection extends Defaul
     @Override
     protected OutputStream createContentOutputStream(final long len,
                                                      final SessionOutputBuffer outbuffer,
+                                                     final OutputStream outputStream,
                                                      final TrailerSupplier trailers) {
         return new CountingOutputStream(
-                super.createContentOutputStream(len, outbuffer, trailers),
+                super.createContentOutputStream(len, outbuffer, outputStream, trailers),
                 this.stats);
     }
 
     @Override
-    protected InputStream createContentInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createContentInputStream(len, inbuffer), this.stats);
+    protected InputStream createContentInputStream(final long len,
+                                                   final SessionInputBuffer inbuffer,
+                                                   final InputStream inputStream) {
+        return new CountingInputStream(super.createContentInputStream(len, inbuffer, inputStream), this.stats);
     }
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java (from r1727859, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpTransportMetricsImpl.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpTransportMetricsImpl.java&r1=1727859&r2=1727970&rev=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpTransportMetricsImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java Mon Feb  1 16:55:59 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.impl.io;
+package org.apache.hc.core5.http.impl;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
 import org.apache.hc.core5.http.io.HttpTransportMetrics;
@@ -36,11 +36,11 @@ import org.apache.hc.core5.http.io.HttpT
  * @since 4.0
  */
 @NotThreadSafe
-public class HttpTransportMetricsImpl implements HttpTransportMetrics {
+public class BasicHttpTransportMetrics implements HttpTransportMetrics {
 
     private long bytesTransferred = 0;
 
-    public HttpTransportMetricsImpl() {
+    public BasicHttpTransportMetrics() {
         super();
     }
 
@@ -49,10 +49,6 @@ public class HttpTransportMetricsImpl im
         return this.bytesTransferred;
     }
 
-    public void setBytesTransferred(final long count) {
-        this.bytesTransferred = count;
-    }
-
     public void incrementBytesTransferred(final long count) {
         this.bytesTransferred += count;
     }

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/BasicHttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageParser.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageParser.java Mon Feb  1 16:55:59 2016
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.impl.io;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -92,6 +93,7 @@ public abstract class AbstractMessagePar
      * format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
      *
      * @param inbuffer Session input buffer
+     * @param inputStream Input stream
      * @param maxHeaderCount maximum number of headers allowed. If the number
      *  of headers received from the data stream exceeds maxCount value, an
      *  IOException will be thrown. Setting this parameter to a negative value
@@ -108,11 +110,12 @@ public abstract class AbstractMessagePar
      */
     public static Header[] parseHeaders(
             final SessionInputBuffer inbuffer,
+            final InputStream inputStream,
             final int maxHeaderCount,
             final int maxLineLen,
             final LineParser lineParser) throws HttpException, IOException {
         final List<CharArrayBuffer> headerLines = new ArrayList<>();
-        return parseHeaders(inbuffer, maxHeaderCount, maxLineLen,
+        return parseHeaders(inbuffer, inputStream, maxHeaderCount, maxLineLen,
                 lineParser != null ? lineParser : LazyLineParser.INSTANCE, headerLines);
     }
 
@@ -121,6 +124,7 @@ public abstract class AbstractMessagePar
      * format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
      *
      * @param inbuffer Session input buffer
+     * @param inputStream Input stream
      * @param maxHeaderCount maximum number of headers allowed. If the number
      *  of headers received from the data stream exceeds maxCount value, an
      *  IOException will be thrown. Setting this parameter to a negative value
@@ -142,11 +146,13 @@ public abstract class AbstractMessagePar
      */
     public static Header[] parseHeaders(
             final SessionInputBuffer inbuffer,
+            final InputStream inputStream,
             final int maxHeaderCount,
             final int maxLineLen,
             final LineParser parser,
             final List<CharArrayBuffer> headerLines) throws HttpException, IOException {
         Args.notNull(inbuffer, "Session input buffer");
+        Args.notNull(inputStream, "Input stream");
         Args.notNull(parser, "Line parser");
         Args.notNull(headerLines, "Header line list");
 
@@ -158,7 +164,7 @@ public abstract class AbstractMessagePar
             } else {
                 current.clear();
             }
-            final int l = inbuffer.readLine(current);
+            final int l = inbuffer.readLine(current, inputStream);
             if (l == -1 || current.length() < 1) {
                 break;
             }
@@ -226,14 +232,15 @@ public abstract class AbstractMessagePar
     protected abstract IOException createConnectionClosedException();
 
     @Override
-    public T parse(final SessionInputBuffer buffer) throws IOException, HttpException {
+    public T parse(final SessionInputBuffer buffer, final InputStream inputStream) throws IOException, HttpException {
         Args.notNull(buffer, "Session input buffer");
+        Args.notNull(inputStream, "Input stream");
         final int st = this.state;
         switch (st) {
         case HEAD_LINE:
             for (int n = 0; n < this.messageConstraints.getMaxEmptyLineCount(); n++) {
                 this.headLine.clear();
-                final int i = buffer.readLine(this.headLine);
+                final int i = buffer.readLine(this.headLine, inputStream);
                 if (i == -1) {
                     throw createConnectionClosedException();
                 }
@@ -250,6 +257,7 @@ public abstract class AbstractMessagePar
         case HEADERS:
             final Header[] headers = AbstractMessageParser.parseHeaders(
                     buffer,
+                    inputStream,
                     this.messageConstraints.getMaxHeaderCount(),
                     this.messageConstraints.getMaxLineLength(),
                     this.lineParser,

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageWriter.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/AbstractMessageWriter.java Mon Feb  1 16:55:59 2016
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.impl.io;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.Iterator;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
@@ -77,29 +78,31 @@ public abstract class AbstractMessageWri
      * based on the {@link HttpMessage} passed as a parameter.
      *
      * @param message the message whose first line is to be written out.
+     * @param lineBuf line buffer
      * @throws IOException in case of an I/O error.
      */
     protected abstract void writeHeadLine(T message, CharArrayBuffer lineBuf) throws IOException;
 
     @Override
-    public void write(final T message, final SessionOutputBuffer buffer) throws IOException, HttpException {
+    public void write(final T message, final SessionOutputBuffer buffer, final OutputStream outputStream) throws IOException, HttpException {
         Args.notNull(message, "HTTP message");
         Args.notNull(buffer, "Session output buffer");
+        Args.notNull(outputStream, "Output stream");
         writeHeadLine(message, this.lineBuf);
-        buffer.writeLine(this.lineBuf);
+        buffer.writeLine(this.lineBuf, outputStream);
         for (final Iterator<Header> it = message.headerIterator(); it.hasNext(); ) {
             final Header header = it.next();
             if (header instanceof FormattedHeader) {
                 final CharArrayBuffer chbuffer = ((FormattedHeader) header).getBuffer();
-                buffer.writeLine(chbuffer);
+                buffer.writeLine(chbuffer, outputStream);
             } else {
                 this.lineBuf.clear();
                 lineFormatter.formatHeader(this.lineBuf, header);
-                buffer.writeLine(this.lineBuf);
+                buffer.writeLine(this.lineBuf, outputStream);
             }
         }
         this.lineBuf.clear();
-        buffer.writeLine(this.lineBuf);
+        buffer.writeLine(this.lineBuf, outputStream);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java Mon Feb  1 16:55:59 2016
@@ -46,6 +46,7 @@ import org.apache.hc.core5.http.HttpHead
 import org.apache.hc.core5.http.HttpMessage;
 import org.apache.hc.core5.http.TrailerSupplier;
 import org.apache.hc.core5.http.config.MessageConstraints;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.impl.HttpConnectionMetricsImpl;
 import org.apache.hc.core5.http.impl.IncomingHttpEntity;
 import org.apache.hc.core5.http.io.BHttpConnection;
@@ -70,8 +71,8 @@ class BHttpConnectionBase implements BHt
             final MessageConstraints messageConstraints) {
         super();
         Args.positive(buffersize, "Buffer size");
-        final HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl();
-        final HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl();
+        final BasicHttpTransportMetrics inTransportMetrics = new BasicHttpTransportMetrics();
+        final BasicHttpTransportMetrics outTransportMetrics = new BasicHttpTransportMetrics();
         this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1,
                 messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder);
         this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint,
@@ -81,17 +82,12 @@ class BHttpConnectionBase implements BHt
         this.socketHolder = new AtomicReference<>();
     }
 
-    protected void ensureOpen() throws IOException {
+    protected Socket ensureOpen() throws IOException {
         final Socket socket = this.socketHolder.get();
         if (socket == null) {
             throw new ConnectionClosedException("Connection is closed");
         }
-        if (!this.inbuffer.isBound()) {
-            this.inbuffer.bind(getSocketInputStream(socket));
-        }
-        if (!this.outbuffer.isBound()) {
-            this.outbuffer.bind(getSocketOutputStream(socket));
-        }
+        return socket;
     }
 
     protected InputStream getSocketInputStream(final Socket socket) throws IOException {
@@ -115,8 +111,6 @@ class BHttpConnectionBase implements BHt
     protected void bind(final Socket socket) throws IOException {
         Args.notNull(socket, "Socket");
         this.socketHolder.set(socket);
-        this.inbuffer.bind(null);
-        this.outbuffer.bind(null);
     }
 
     @Override
@@ -130,37 +124,40 @@ class BHttpConnectionBase implements BHt
 
     protected OutputStream createContentOutputStream(
             final long len,
-            final SessionOutputBuffer outbuffer,
+            final SessionOutputBuffer buffer,
+            final OutputStream outputStream,
             final TrailerSupplier trailers) {
         if (len >= 0) {
-            return new ContentLengthOutputStream(outbuffer, len);
+            return new ContentLengthOutputStream(buffer, outputStream, len);
         } else if (len == ContentLengthStrategy.CHUNKED) {
-            return new ChunkedOutputStream(2048, outbuffer, trailers);
+            return new ChunkedOutputStream(2048, buffer, outputStream, trailers);
         } else {
-            return new IdentityOutputStream(outbuffer);
+            return new IdentityOutputStream(buffer, outputStream);
         }
     }
 
     protected InputStream createContentInputStream(
             final long len,
-            final SessionInputBuffer inbuffer) {
+            final SessionInputBuffer buffer,
+            final InputStream inputStream) {
         if (len > 0) {
-            return new ContentLengthInputStream(inbuffer, len);
+            return new ContentLengthInputStream(buffer, inputStream, len);
         } else if (len == 0) {
             return EmptyInputStream.INSTANCE;
         } else if (len == ContentLengthStrategy.CHUNKED) {
-            return new ChunkedInputStream(inbuffer, this.messageConstraints);
+            return new ChunkedInputStream(buffer, inputStream, this.messageConstraints);
         } else {
-            return new IdentityInputStream(inbuffer);
+            return new IdentityInputStream(buffer, inputStream);
         }
     }
 
     HttpEntity createIncomingEntity(
             final HttpMessage message,
             final SessionInputBuffer inbuffer,
+            final InputStream inputStream,
             final long len) {
         return new IncomingHttpEntity(
-                createContentInputStream(len, inbuffer),
+                createContentInputStream(len, inbuffer, inputStream),
                 len >= 0 ? len : -1, len == ContentLengthStrategy.CHUNKED,
                 message.getFirstHeader(HttpHeaders.CONTENT_TYPE),
                 message.getFirstHeader(HttpHeaders.CONTENT_ENCODING));
@@ -225,7 +222,7 @@ class BHttpConnectionBase implements BHt
         if (socket != null) {
             try {
                 this.inbuffer.clear();
-                this.outbuffer.flush();
+                this.outbuffer.flush(socket.getOutputStream());
                 try {
                     try {
                         socket.shutdownOutput();
@@ -249,7 +246,7 @@ class BHttpConnectionBase implements BHt
         final int oldtimeout = socket.getSoTimeout();
         try {
             socket.setSoTimeout(timeout);
-            return this.inbuffer.fillBuffer();
+            return this.inbuffer.fillBuffer(socket.getInputStream());
         } finally {
             socket.setSoTimeout(oldtimeout);
         }
@@ -290,8 +287,8 @@ class BHttpConnectionBase implements BHt
 
     @Override
     public void flush() throws IOException {
-        ensureOpen();
-        this.outbuffer.flush();
+        final Socket socket = ensureOpen();
+        this.outbuffer.flush(socket.getOutputStream());
     }
 
     protected void incrementRequestCount() {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java Mon Feb  1 16:55:59 2016
@@ -68,8 +68,9 @@ public class ChunkedInputStream extends
     private static final int BUFFER_SIZE = 2048;
 
     /** The session input buffer */
-    private final SessionInputBuffer in;
-    private final CharArrayBuffer buffer;
+    private final SessionInputBuffer buffer;
+    private final InputStream inputStream;
+    private final CharArrayBuffer lineBuffer;
     private final MessageConstraints constraints;
 
     private int state;
@@ -89,19 +90,20 @@ public class ChunkedInputStream extends
     private Header[] footers = new Header[] {};
 
     /**
-     * Wraps session input stream and reads chunk coded input.
+     * Default constructor.
      *
-     * @param in The session input buffer
-     * @param constraints Message constraints. If {@code null}
-     *   {@link MessageConstraints#DEFAULT} will be used.
+     * @param buffer Session input buffer
+     * @param inputStream Input stream
+     * @param constraints Message constraints. If {@code null} {@link MessageConstraints#DEFAULT} will be used.
      *
      * @since 4.4
      */
-    public ChunkedInputStream(final SessionInputBuffer in, final MessageConstraints constraints) {
+    public ChunkedInputStream(final SessionInputBuffer buffer, final InputStream inputStream, final MessageConstraints constraints) {
         super();
-        this.in = Args.notNull(in, "Session input buffer");
+        this.buffer = Args.notNull(buffer, "Session input buffer");
+        this.inputStream = Args.notNull(inputStream, "Input stream");
         this.pos = 0;
-        this.buffer = new CharArrayBuffer(16);
+        this.lineBuffer = new CharArrayBuffer(16);
         this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
         this.state = CHUNK_LEN;
     }
@@ -109,15 +111,16 @@ public class ChunkedInputStream extends
     /**
      * Wraps session input stream and reads chunk coded input.
      *
-     * @param in The session input buffer
+     * @param buffer Session input buffer
+     * @param inputStream Input stream
      */
-    public ChunkedInputStream(final SessionInputBuffer in) {
-        this(in, null);
+    public ChunkedInputStream(final SessionInputBuffer buffer, final InputStream inputStream) {
+        this(buffer, inputStream, null);
     }
 
     @Override
     public int available() throws IOException {
-        final int len = this.in.length();
+        final int len = this.buffer.length();
         return Math.min(len, this.chunkSize - this.pos);
     }
 
@@ -147,7 +150,7 @@ public class ChunkedInputStream extends
                 return -1;
             }
         }
-        final int b = in.read();
+        final int b = buffer.read(inputStream);
         if (b != -1) {
             pos++;
             if (pos >= chunkSize) {
@@ -183,7 +186,7 @@ public class ChunkedInputStream extends
                 return -1;
             }
         }
-        final int bytesRead = in.read(b, off, Math.min(len, chunkSize - pos));
+        final int bytesRead = buffer.read(b, off, Math.min(len, chunkSize - pos), inputStream);
         if (bytesRead != -1) {
             pos += bytesRead;
             if (pos >= chunkSize) {
@@ -243,31 +246,31 @@ public class ChunkedInputStream extends
         final int st = this.state;
         switch (st) {
         case CHUNK_CRLF:
-            this.buffer.clear();
-            final int bytesRead1 = this.in.readLine(this.buffer);
+            lineBuffer.clear();
+            final int bytesRead1 = this.buffer.readLine(lineBuffer, inputStream);
             if (bytesRead1 == -1) {
                 throw new MalformedChunkCodingException(
                     "CRLF expected at end of chunk");
             }
-            if (!this.buffer.isEmpty()) {
+            if (!lineBuffer.isEmpty()) {
                 throw new MalformedChunkCodingException(
                     "Unexpected content at the end of chunk");
             }
             state = CHUNK_LEN;
             //$FALL-THROUGH$
         case CHUNK_LEN:
-            this.buffer.clear();
-            final int bytesRead2 = this.in.readLine(this.buffer);
+            lineBuffer.clear();
+            final int bytesRead2 = this.buffer.readLine(lineBuffer, inputStream);
             if (bytesRead2 == -1) {
                 throw new ConnectionClosedException("Premature end of chunk coded message body: " +
                         "closing chunk expected");
             }
-            int separator = this.buffer.indexOf(';');
+            int separator = lineBuffer.indexOf(';');
             if (separator < 0) {
-                separator = this.buffer.length();
+                separator = lineBuffer.length();
             }
             try {
-                return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
+                return Integer.parseInt(lineBuffer.substringTrimmed(0, separator), 16);
             } catch (final NumberFormatException e) {
                 throw new MalformedChunkCodingException("Bad chunk header");
             }
@@ -282,7 +285,7 @@ public class ChunkedInputStream extends
      */
     private void parseTrailerHeaders() throws IOException {
         try {
-            this.footers = AbstractMessageParser.parseHeaders(in,
+            this.footers = AbstractMessageParser.parseHeaders(buffer, inputStream,
                     constraints.getMaxHeaderCount(),
                     constraints.getMaxLineLength(),
                     null);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedOutputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedOutputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedOutputStream.java Mon Feb  1 16:55:59 2016
@@ -36,6 +36,7 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.TrailerSupplier;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
 
 /**
@@ -53,59 +54,57 @@ import org.apache.hc.core5.util.CharArra
 @NotThreadSafe
 public class ChunkedOutputStream extends OutputStream {
 
-    // ----------------------------------------------------- Instance Variables
-    private final SessionOutputBuffer out;
+    private final SessionOutputBuffer buffer;
+    private final OutputStream outputStream;
 
     private final byte[] cache;
-
     private int cachePosition = 0;
-
     private boolean wroteLastChunk = false;
-
-    /** True if the stream is closed. */
     private boolean closed = false;
-
-    private final CharArrayBuffer linebuffer;
-
+    private final CharArrayBuffer lineBuffer;
     private final TrailerSupplier trailers;
 
     /**
-     * Wraps a session output buffer and chunk-encodes the output.
+     * Default constructor.
      *
-     * @param bufferSize The minimum chunk size (excluding last chunk)
-     * @param out The session output buffer
+     * @param minChunkSize The minimum chunk size (excluding last chunk)
+     * @param buffer Session output buffer
+     * @param outputStream Output stream
+     * @param trailers Trailer supplier. May be {@code null}
      *
      * @since 5.0
      */
-    public ChunkedOutputStream(final int bufferSize, final SessionOutputBuffer out, final TrailerSupplier trailers) {
+    public ChunkedOutputStream(final int minChunkSize, final SessionOutputBuffer buffer, final OutputStream outputStream, final TrailerSupplier trailers) {
         super();
-        this.cache = new byte[bufferSize];
-        this.out = out;
-        this.linebuffer = new CharArrayBuffer(32);
+        this.buffer = Args.notNull(buffer, "Session output buffer");
+        this.outputStream = Args.notNull(outputStream, "Output stream");
+        this.cache = new byte[minChunkSize];
+        this.lineBuffer = new CharArrayBuffer(32);
         this.trailers = trailers;
     }
 
     /**
-     * Wraps a session output buffer and chunk-encodes the output.
+     * Constructor with no trailers.
      *
-     * @param bufferSize The minimum chunk size (excluding last chunk)
-     * @param out The session output buffer
+     * @param minChunkSize The minimum chunk size (excluding last chunk)
+     * @param buffer Session output buffer
+     * @param outputStream Output stream
      */
-    public ChunkedOutputStream(final int bufferSize, final SessionOutputBuffer out) {
-        this(bufferSize, out, null);
+    public ChunkedOutputStream(final int minChunkSize, final SessionOutputBuffer buffer, final OutputStream outputStream) {
+        this(minChunkSize, buffer, outputStream, null);
     }
 
     /**
      * Writes the cache out onto the underlying stream
      */
-    protected void flushCache() throws IOException {
+    private void flushCache() throws IOException {
         if (this.cachePosition > 0) {
-            this.linebuffer.clear();
-            this.linebuffer.append(Integer.toHexString(this.cachePosition));
-            this.out.writeLine(this.linebuffer);
-            this.out.write(this.cache, 0, this.cachePosition);
-            this.linebuffer.clear();
-            this.out.writeLine(this.linebuffer);
+            this.lineBuffer.clear();
+            this.lineBuffer.append(Integer.toHexString(this.cachePosition));
+            this.buffer.writeLine(this.lineBuffer, this.outputStream);
+            this.buffer.write(this.cache, 0, this.cachePosition, this.outputStream);
+            this.lineBuffer.clear();
+            this.buffer.writeLine(this.lineBuffer, this.outputStream);
             this.cachePosition = 0;
         }
     }
@@ -114,25 +113,25 @@ public class ChunkedOutputStream extends
      * Writes the cache and bufferToAppend to the underlying stream
      * as one large chunk
      */
-    protected void flushCacheWithAppend(final byte bufferToAppend[], final int off, final int len) throws IOException {
-        this.linebuffer.clear();
-        this.linebuffer.append(Integer.toHexString(this.cachePosition + len));
-        this.out.writeLine(this.linebuffer);
-        this.out.write(this.cache, 0, this.cachePosition);
-        this.out.write(bufferToAppend, off, len);
-        this.linebuffer.clear();
-        this.out.writeLine(this.linebuffer);
+    private void flushCacheWithAppend(final byte bufferToAppend[], final int off, final int len) throws IOException {
+        this.lineBuffer.clear();
+        this.lineBuffer.append(Integer.toHexString(this.cachePosition + len));
+        this.buffer.writeLine(this.lineBuffer, this.outputStream);
+        this.buffer.write(this.cache, 0, this.cachePosition, this.outputStream);
+        this.buffer.write(bufferToAppend, off, len, this.outputStream);
+        this.lineBuffer.clear();
+        this.buffer.writeLine(this.lineBuffer, this.outputStream);
         this.cachePosition = 0;
     }
 
-    protected void writeClosingChunk() throws IOException {
+    private void writeClosingChunk() throws IOException {
         // Write the final chunk.
-        this.linebuffer.clear();
-        this.linebuffer.append('0');
-        this.out.writeLine(this.linebuffer);
+        this.lineBuffer.clear();
+        this.lineBuffer.append('0');
+        this.buffer.writeLine(this.lineBuffer, this.outputStream);
         writeTrailers();
-        this.linebuffer.clear();
-        this.out.writeLine(this.linebuffer);
+        this.lineBuffer.clear();
+        this.buffer.writeLine(this.lineBuffer, this.outputStream);
     }
 
     private void writeTrailers() throws IOException {
@@ -141,11 +140,11 @@ public class ChunkedOutputStream extends
             for (final Header header: headers) {
                 if (header instanceof FormattedHeader) {
                     final CharArrayBuffer chbuffer = ((FormattedHeader) header).getBuffer();
-                    this.out.writeLine(chbuffer);
+                    this.buffer.writeLine(chbuffer, this.outputStream);
                 } else {
-                    this.linebuffer.clear();
-                    BasicLineFormatter.INSTANCE.formatHeader(this.linebuffer, header);
-                    this.out.writeLine(this.linebuffer);
+                    this.lineBuffer.clear();
+                    BasicLineFormatter.INSTANCE.formatHeader(this.lineBuffer, header);
+                    this.buffer.writeLine(this.lineBuffer, this.outputStream);
                 }
             }
         }
@@ -210,7 +209,7 @@ public class ChunkedOutputStream extends
     @Override
     public void flush() throws IOException {
         flushCache();
-        this.out.flush();
+        this.buffer.flush(this.outputStream);
     }
 
     /**
@@ -221,7 +220,7 @@ public class ChunkedOutputStream extends
         if (!this.closed) {
             this.closed = true;
             finish();
-            this.out.flush();
+            this.buffer.flush(this.outputStream);
         }
     }
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java Mon Feb  1 16:55:59 2016
@@ -55,6 +55,10 @@ import org.apache.hc.core5.util.Args;
 public class ContentLengthInputStream extends InputStream {
 
     private static final int BUFFER_SIZE = 2048;
+
+    private final SessionInputBuffer buffer;
+    private final InputStream inputStream;
+
     /**
      * The maximum number of bytes that can be read from the stream. Subsequent
      * read operations will return -1.
@@ -68,21 +72,17 @@ public class ContentLengthInputStream ex
     private boolean closed = false;
 
     /**
-     * Wrapped input stream that all calls are delegated to.
-     */
-    private SessionInputBuffer in = null;
-
-    /**
-     * Wraps a session input buffer and cuts off output after a defined number
-     * of bytes.
+     * Default constructor.
      *
-     * @param in The session input buffer
+     * @param buffer Session input buffer
+     * @param inputStream Input stream
      * @param contentLength The maximum number of bytes that can be read from
      * the stream. Subsequent read operations will return -1.
      */
-    public ContentLengthInputStream(final SessionInputBuffer in, final long contentLength) {
+    public ContentLengthInputStream(final SessionInputBuffer buffer, final InputStream inputStream, final long contentLength) {
         super();
-        this.in = Args.notNull(in, "Session input buffer");
+        this.buffer = Args.notNull(buffer, "Session input buffer");
+        this.inputStream = Args.notNull(inputStream, "Input stream");
         this.contentLength = Args.notNegative(contentLength, "Content length");
     }
 
@@ -112,7 +112,7 @@ public class ContentLengthInputStream ex
 
     @Override
     public int available() throws IOException {
-        final int len = this.in.length();
+        final int len = this.buffer.length();
         return Math.min(len, (int) (this.contentLength - this.pos));
     }
 
@@ -131,7 +131,7 @@ public class ContentLengthInputStream ex
         if (pos >= contentLength) {
             return -1;
         }
-        final int b = this.in.read();
+        final int b = this.buffer.read(this.inputStream);
         if (b == -1) {
             if (pos < contentLength) {
                 throw new ConnectionClosedException(
@@ -170,7 +170,7 @@ public class ContentLengthInputStream ex
         if (pos + len > contentLength) {
             chunk = (int) (contentLength - pos);
         }
-        final int count = this.in.read(b, off, chunk);
+        final int count = this.buffer.read(b, off, chunk, this.inputStream);
         if (count == -1 && pos < contentLength) {
             throw new ConnectionClosedException(
                     "Premature end of Content-Length delimited message body (expected: "

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthOutputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthOutputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthOutputStream.java Mon Feb  1 16:55:59 2016
@@ -50,10 +50,8 @@ import org.apache.hc.core5.util.Args;
 @NotThreadSafe
 public class ContentLengthOutputStream extends OutputStream {
 
-    /**
-     * Wrapped session output buffer.
-     */
-    private final SessionOutputBuffer out;
+    private final SessionOutputBuffer buffer;
+    private final OutputStream outputStream;
 
     /**
      * The maximum number of bytes that can be written the stream. Subsequent
@@ -68,18 +66,19 @@ public class ContentLengthOutputStream e
     private boolean closed = false;
 
     /**
-     * Wraps a session output buffer and cuts off output after a defined number
-     * of bytes.
+     * Default constructor.
      *
-     * @param out The session output buffer
+     * @param buffer Session output buffer
+     * @param outputStream Output stream
      * @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 SessionOutputBuffer out, final long contentLength) {
+    public ContentLengthOutputStream(final SessionOutputBuffer buffer, final OutputStream outputStream, final long contentLength) {
         super();
-        this.out = Args.notNull(out, "Session output buffer");
+        this.buffer = Args.notNull(buffer, "Session output buffer");
+        this.outputStream = Args.notNull(outputStream, "Output stream");
         this.contentLength = Args.notNegative(contentLength, "Content length");
     }
 
@@ -92,13 +91,13 @@ public class ContentLengthOutputStream e
     public void close() throws IOException {
         if (!this.closed) {
             this.closed = true;
-            this.out.flush();
+            this.buffer.flush(this.outputStream);
         }
     }
 
     @Override
     public void flush() throws IOException {
-        this.out.flush();
+        this.buffer.flush(this.outputStream);
     }
 
     @Override
@@ -112,7 +111,7 @@ public class ContentLengthOutputStream e
             if (chunk > max) {
                 chunk = (int) max;
             }
-            this.out.write(b, off, chunk);
+            this.buffer.write(b, off, chunk, this.outputStream);
             this.total += chunk;
         }
     }
@@ -128,7 +127,7 @@ public class ContentLengthOutputStream e
             throw new IOException("Attempted write to closed stream.");
         }
         if (this.total < this.contentLength) {
-            this.out.write(b);
+            this.buffer.write(b, this.outputStream);
             this.total++;
         }
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java Mon Feb  1 16:55:59 2016
@@ -134,8 +134,8 @@ public class DefaultBHttpClientConnectio
     public void sendRequestHeader(final HttpRequest request)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        ensureOpen();
-        this.requestWriter.write(request, this.outbuffer);
+        final Socket socket = ensureOpen();
+        this.requestWriter.write(request, this.outbuffer, socket.getOutputStream());
         onRequestSubmitted(request);
         incrementRequestCount();
     }
@@ -143,7 +143,7 @@ public class DefaultBHttpClientConnectio
     @Override
     public void sendRequestEntity(final HttpRequest request) throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        ensureOpen();
+        final Socket socket = ensureOpen();
         final HttpEntity entity = request.getEntity();
         if (entity == null) {
             return;
@@ -152,7 +152,7 @@ public class DefaultBHttpClientConnectio
         if (len == ContentLengthStrategy.UNDEFINED) {
             throw new LengthRequiredException("Length required");
         }
-        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, entity.getTrailers());
+        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socket.getOutputStream(), entity.getTrailers());
         entity.writeTo(outstream);
         outstream.close();
     }
@@ -165,17 +165,17 @@ public class DefaultBHttpClientConnectio
     @Override
     public void terminateRequest(final HttpRequest request) throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        ensureOpen();
+        final Socket socket = ensureOpen();
         final HttpEntity entity = request.getEntity();
         if (entity == null) {
             return;
         }
         final long len = this.outgoingContentStrategy.determineLength(request);
         if (len == ContentLengthStrategy.CHUNKED) {
-            final OutputStream outstream = createContentOutputStream(len, this.outbuffer, entity.getTrailers());
+            final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socket.getOutputStream(), entity.getTrailers());
             outstream.close();
         } else if (len >= 0 && len <= 1024) {
-            final OutputStream outstream = createContentOutputStream(len, this.outbuffer, null);
+            final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socket.getOutputStream(), null);
             entity.writeTo(outstream);
             outstream.close();
         } else {
@@ -185,8 +185,8 @@ public class DefaultBHttpClientConnectio
 
     @Override
     public HttpResponse receiveResponseHeader() throws HttpException, IOException {
-        ensureOpen();
-        final HttpResponse response = this.responseParser.parse(this.inbuffer);
+        final Socket socket = ensureOpen();
+        final HttpResponse response = this.responseParser.parse(this.inbuffer, socket.getInputStream());
         onResponseReceived(response);
         if (response.getCode() >= HttpStatus.SC_SUCCESS) {
             incrementResponseCount();
@@ -195,14 +195,13 @@ public class DefaultBHttpClientConnectio
     }
 
     @Override
-    public void receiveResponseEntity(
-            final HttpResponse response) throws HttpException, IOException {
+    public void receiveResponseEntity( final HttpResponse response) throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        ensureOpen();
+        final Socket socket = ensureOpen();
         final long len = this.incomingContentStrategy.determineLength(response);
         if (len == ContentLengthStrategy.UNDEFINED) {
             return;
         }
-        response.setEntity(createIncomingEntity(response, this.inbuffer, len));
+        response.setEntity(createIncomingEntity(response, this.inbuffer, socket.getInputStream(), len));
     }
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java Mon Feb  1 16:55:59 2016
@@ -128,10 +128,9 @@ public class DefaultBHttpServerConnectio
     }
 
     @Override
-    public HttpRequest receiveRequestHeader()
-            throws HttpException, IOException {
-        ensureOpen();
-        final HttpRequest request = this.requestParser.parse(this.inbuffer);
+    public HttpRequest receiveRequestHeader() throws HttpException, IOException {
+        final Socket socket = ensureOpen();
+        final HttpRequest request = this.requestParser.parse(this.inbuffer, socket.getInputStream());
         onRequestReceived(request);
         incrementRequestCount();
         return request;
@@ -141,13 +140,13 @@ public class DefaultBHttpServerConnectio
     public void receiveRequestEntity(final HttpRequest request)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
-        ensureOpen();
+        final Socket socket = ensureOpen();
 
         final long len = this.incomingContentStrategy.determineLength(request);
         if (len == ContentLengthStrategy.UNDEFINED) {
             return;
         }
-        final HttpEntity entity = createIncomingEntity(request, this.inbuffer, len);
+        final HttpEntity entity = createIncomingEntity(request, this.inbuffer, socket.getInputStream(), len);
         request.setEntity(entity);
     }
 
@@ -155,8 +154,8 @@ public class DefaultBHttpServerConnectio
     public void sendResponseHeader(final HttpResponse response)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        ensureOpen();
-        this.responseWriter.write(response, this.outbuffer);
+        final Socket socket = ensureOpen();
+        this.responseWriter.write(response, this.outbuffer, socket.getOutputStream());
         onResponseSubmitted(response);
         if (response.getCode() >= HttpStatus.SC_SUCCESS) {
             incrementResponseCount();
@@ -167,13 +166,13 @@ public class DefaultBHttpServerConnectio
     public void sendResponseEntity(final HttpResponse response)
             throws HttpException, IOException {
         Args.notNull(response, "HTTP response");
-        ensureOpen();
+        final Socket socket = ensureOpen();
         final HttpEntity entity = response.getEntity();
         if (entity == null) {
             return;
         }
         final long len = this.outgoingContentStrategy.determineLength(response);
-        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, entity.getTrailers());
+        final OutputStream outstream = createContentOutputStream(len, this.outbuffer, socket.getOutputStream(), entity.getTrailers());
         entity.writeTo(outstream);
         outstream.close();
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityInputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityInputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityInputStream.java Mon Feb  1 16:55:59 2016
@@ -49,23 +49,26 @@ import org.apache.hc.core5.util.Args;
 @NotThreadSafe
 public class IdentityInputStream extends InputStream {
 
-    private final SessionInputBuffer in;
+    private final SessionInputBuffer buffer;
+    private final InputStream inputStream;
 
     private boolean closed = false;
 
     /**
-     * Wraps session input stream and reads input until the the end of stream.
+     * Default constructor.
      *
-     * @param in The session input buffer
+     * @param buffer Session input buffer
+     * @param inputStream Input stream
      */
-    public IdentityInputStream(final SessionInputBuffer in) {
+    public IdentityInputStream(final SessionInputBuffer buffer, final InputStream inputStream) {
         super();
-        this.in = Args.notNull(in, "Session input buffer");
+        this.buffer = Args.notNull(buffer, "Session input buffer");
+        this.inputStream = Args.notNull(inputStream, "Input stream");
     }
 
     @Override
     public int available() throws IOException {
-        return this.in.length();
+        return this.buffer.length();
     }
 
     @Override
@@ -78,7 +81,7 @@ public class IdentityInputStream extends
         if (this.closed) {
             return -1;
         }
-        return this.in.read();
+        return this.buffer.read(this.inputStream);
     }
 
     @Override
@@ -86,7 +89,7 @@ public class IdentityInputStream extends
         if (this.closed) {
             return -1;
         }
-        return this.in.read(b, off, len);
+        return this.buffer.read(b, off, len, this.inputStream);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityOutputStream.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityOutputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/IdentityOutputStream.java Mon Feb  1 16:55:59 2016
@@ -49,17 +49,22 @@ import org.apache.hc.core5.util.Args;
 @NotThreadSafe
 public class IdentityOutputStream extends OutputStream {
 
-    /**
-     * Wrapped session output buffer.
-     */
-    private final SessionOutputBuffer out;
+    private final SessionOutputBuffer buffer;
+    private final OutputStream outputStream;
 
     /** True if the stream is closed. */
     private boolean closed = false;
 
-    public IdentityOutputStream(final SessionOutputBuffer out) {
+    /**
+     * Default constructor.
+     *
+     * @param buffer Session output buffer
+     * @param outputStream Output stream
+     */
+    public IdentityOutputStream(final SessionOutputBuffer buffer, final OutputStream outputStream) {
         super();
-        this.out = Args.notNull(out, "Session output buffer");
+        this.buffer = Args.notNull(buffer, "Session output buffer");
+        this.outputStream = Args.notNull(outputStream, "Output stream");
     }
 
     /**
@@ -71,13 +76,13 @@ public class IdentityOutputStream extend
     public void close() throws IOException {
         if (!this.closed) {
             this.closed = true;
-            this.out.flush();
+            this.buffer.flush(this.outputStream);
         }
     }
 
     @Override
     public void flush() throws IOException {
-        this.out.flush();
+        this.buffer.flush(this.outputStream);
     }
 
     @Override
@@ -85,7 +90,7 @@ public class IdentityOutputStream extend
         if (this.closed) {
             throw new IOException("Attempted write to closed stream.");
         }
-        this.out.write(b, off, len);
+        this.buffer.write(b, off, len, this.outputStream);
     }
 
     @Override
@@ -98,7 +103,7 @@ public class IdentityOutputStream extend
         if (this.closed) {
             throw new IOException("Attempted write to closed stream.");
         }
-        this.out.write(b);
+        this.buffer.write(b, this.outputStream);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java Mon Feb  1 16:55:59 2016
@@ -38,10 +38,10 @@ import org.apache.hc.core5.annotation.No
 import org.apache.hc.core5.http.Chars;
 import org.apache.hc.core5.http.MessageConstraintException;
 import org.apache.hc.core5.http.config.MessageConstraints;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.io.HttpTransportMetrics;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.ByteArrayBuffer;
 import org.apache.hc.core5.util.CharArrayBuffer;
 
@@ -50,7 +50,7 @@ import org.apache.hc.core5.util.CharArra
  * an arbitrary {@link InputStream}. This class buffers input data in
  * an internal byte array for optimal input performance.
  * <p>
- * {@link #readLine(CharArrayBuffer)} method of this class treat a lone
+ * {@link #readLine(CharArrayBuffer, InputStream)} method of this class treat a lone
  * LF as valid line delimiters in addition to CR-LF required
  * by the HTTP specification.
  *
@@ -59,14 +59,13 @@ import org.apache.hc.core5.util.CharArra
 @NotThreadSafe
 public class SessionInputBufferImpl implements SessionInputBuffer {
 
-    private final HttpTransportMetricsImpl metrics;
+    private final BasicHttpTransportMetrics metrics;
     private final byte[] buffer;
     private final ByteArrayBuffer linebuffer;
     private final int minChunkLimit;
     private final MessageConstraints constraints;
     private final CharsetDecoder decoder;
 
-    private InputStream instream;
     private int bufferpos;
     private int bufferlen;
     private CharBuffer cbuf;
@@ -87,7 +86,7 @@ public class SessionInputBufferImpl impl
      *   If {@code null} simple type cast will be used for byte to char conversion.
      */
     public SessionInputBufferImpl(
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final int buffersize,
             final int minChunkLimit,
             final MessageConstraints constraints,
@@ -105,17 +104,21 @@ public class SessionInputBufferImpl impl
     }
 
     public SessionInputBufferImpl(
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final int buffersize) {
         this(metrics, buffersize, buffersize, null, null);
     }
 
-    public void bind(final InputStream instream) {
-        this.instream = instream;
+    public SessionInputBufferImpl(final int buffersize, final MessageConstraints constraints) {
+        this(new BasicHttpTransportMetrics(), buffersize, buffersize, constraints, null);
     }
 
-    public boolean isBound() {
-        return this.instream != null;
+    public SessionInputBufferImpl(final int buffersize, final CharsetDecoder decoder) {
+        this(new BasicHttpTransportMetrics(), buffersize, buffersize, null, decoder);
+    }
+
+    public SessionInputBufferImpl(final int buffersize) {
+        this(new BasicHttpTransportMetrics(), buffersize, buffersize, null, null);
     }
 
     @Override
@@ -133,12 +136,8 @@ public class SessionInputBufferImpl impl
         return capacity() - length();
     }
 
-    private int streamRead(final byte[] b, final int off, final int len) throws IOException {
-        Asserts.notNull(this.instream, "Input stream");
-        return this.instream.read(b, off, len);
-    }
-
-    public int fillBuffer() throws IOException {
+    public int fillBuffer(final InputStream inputStream) throws IOException {
+        Args.notNull(inputStream, "Input stream");
         // compact the buffer if necessary
         if (this.bufferpos > 0) {
             final int len = this.bufferlen - this.bufferpos;
@@ -151,7 +150,7 @@ public class SessionInputBufferImpl impl
         final int l;
         final int off = this.bufferlen;
         final int len = this.buffer.length - off;
-        l = streamRead(this.buffer, off, len);
+        l = inputStream.read(this.buffer, off, len);
         if (l == -1) {
             return -1;
         }
@@ -170,10 +169,11 @@ public class SessionInputBufferImpl impl
     }
 
     @Override
-    public int read() throws IOException {
+    public int read(final InputStream inputStream) throws IOException {
+        Args.notNull(inputStream, "Input stream");
         int noRead;
         while (!hasBufferedData()) {
-            noRead = fillBuffer();
+            noRead = fillBuffer(inputStream);
             if (noRead == -1) {
                 return -1;
             }
@@ -182,7 +182,8 @@ public class SessionInputBufferImpl impl
     }
 
     @Override
-    public int read(final byte[] b, final int off, final int len) throws IOException {
+    public int read(final byte[] b, final int off, final int len, final InputStream inputStream) throws IOException {
+        Args.notNull(inputStream, "Input stream");
         if (b == null) {
             return 0;
         }
@@ -195,7 +196,7 @@ public class SessionInputBufferImpl impl
         // If the remaining capacity is big enough, read directly from the
         // underlying input stream bypassing the buffer.
         if (len > this.minChunkLimit) {
-            final int read = streamRead(b, off, len);
+            final int read = inputStream.read(b, off, len);
             if (read > 0) {
                 this.metrics.incrementBytesTransferred(read);
             }
@@ -203,7 +204,7 @@ public class SessionInputBufferImpl impl
         }
         // otherwise read to the buffer first
         while (!hasBufferedData()) {
-            final int noRead = fillBuffer();
+            final int noRead = fillBuffer(inputStream);
             if (noRead == -1) {
                 return -1;
             }
@@ -215,11 +216,11 @@ public class SessionInputBufferImpl impl
     }
 
     @Override
-    public int read(final byte[] b) throws IOException {
+    public int read(final byte[] b, final InputStream inputStream) throws IOException {
         if (b == null) {
             return 0;
         }
-        return read(b, 0, b.length);
+        return read(b, 0, b.length, inputStream);
     }
 
     /**
@@ -238,8 +239,9 @@ public class SessionInputBufferImpl impl
      * @exception  IOException  if an I/O error occurs.
      */
     @Override
-    public int readLine(final CharArrayBuffer charbuffer) throws IOException {
+    public int readLine(final CharArrayBuffer charbuffer, final InputStream inputStream) throws IOException {
         Args.notNull(charbuffer, "Char array buffer");
+        Args.notNull(inputStream, "Input stream");
         final int maxLineLen = this.constraints.getMaxLineLength();
         int noRead = 0;
         boolean retry = true;
@@ -278,7 +280,7 @@ public class SessionInputBufferImpl impl
                     this.linebuffer.append(this.buffer, this.bufferpos, len);
                     this.bufferpos = this.bufferlen;
                 }
-                noRead = fillBuffer();
+                noRead = fillBuffer(inputStream);
                 if (noRead == -1) {
                     retry = false;
                 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java Mon Feb  1 16:55:59 2016
@@ -36,10 +36,10 @@ import java.nio.charset.CoderResult;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
 import org.apache.hc.core5.http.Chars;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.io.HttpTransportMetrics;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.ByteArrayBuffer;
 import org.apache.hc.core5.util.CharArrayBuffer;
 
@@ -48,7 +48,7 @@ import org.apache.hc.core5.util.CharArra
  * an arbitrary {@link OutputStream}. This class buffers small chunks of
  * output data in an internal byte array for optimal output performance.
  * <p>
- * {@link #writeLine(CharArrayBuffer)} method of this class uses CR-LF
+ * {@link #writeLine(CharArrayBuffer, OutputStream)} method of this class uses CR-LF
  * as a line delimiter.
  *
  * @since 4.3
@@ -58,12 +58,11 @@ public class SessionOutputBufferImpl imp
 
     private static final byte[] CRLF = new byte[] {Chars.CR, Chars.LF};
 
-    private final HttpTransportMetricsImpl metrics;
+    private final BasicHttpTransportMetrics metrics;
     private final ByteArrayBuffer buffer;
     private final int fragementSizeHint;
     private final CharsetEncoder encoder;
 
-    private OutputStream outstream;
     private ByteBuffer bbuf;
 
     /**
@@ -78,7 +77,7 @@ public class SessionOutputBufferImpl imp
      *   If {@code null} simple type cast will be used for char to byte conversion.
      */
     public SessionOutputBufferImpl(
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final int buffersize,
             final int fragementSizeHint,
             final CharsetEncoder charencoder) {
@@ -91,18 +90,12 @@ public class SessionOutputBufferImpl imp
         this.encoder = charencoder;
     }
 
-    public SessionOutputBufferImpl(
-            final HttpTransportMetricsImpl metrics,
-            final int buffersize) {
-        this(metrics, buffersize, buffersize, null);
-    }
-
-    public void bind(final OutputStream outstream) {
-        this.outstream = outstream;
+    public SessionOutputBufferImpl(final int buffersize) {
+        this(new BasicHttpTransportMetrics(), buffersize, buffersize, null);
     }
 
-    public boolean isBound() {
-        return this.outstream != null;
+    public SessionOutputBufferImpl(final int buffersize, final CharsetEncoder encoder) {
+        this(new BasicHttpTransportMetrics(), buffersize, buffersize, encoder);
     }
 
     @Override
@@ -120,52 +113,43 @@ public class SessionOutputBufferImpl imp
         return capacity() - length();
     }
 
-    private void streamWrite(final byte[] b, final int off, final int len) throws IOException {
-        Asserts.notNull(outstream, "Output stream");
-        this.outstream.write(b, off, len);
-    }
-
-    private void flushStream() throws IOException {
-        if (this.outstream != null) {
-            this.outstream.flush();
-        }
-    }
-
-    private void flushBuffer() throws IOException {
+    private void flushBuffer(final OutputStream outputStream) throws IOException {
         final int len = this.buffer.length();
         if (len > 0) {
-            streamWrite(this.buffer.buffer(), 0, len);
+            outputStream.write(this.buffer.buffer(), 0, len);
             this.buffer.clear();
             this.metrics.incrementBytesTransferred(len);
         }
     }
 
     @Override
-    public void flush() throws IOException {
-        flushBuffer();
-        flushStream();
+    public void flush(final OutputStream outputStream) throws IOException {
+        Args.notNull(outputStream, "Output stream");
+        flushBuffer(outputStream);
+        outputStream.flush();
     }
 
     @Override
-    public void write(final byte[] b, final int off, final int len) throws IOException {
+    public void write(final byte[] b, final int off, final int len, final OutputStream outputStream) throws IOException {
         if (b == null) {
             return;
         }
+        Args.notNull(outputStream, "Output stream");
         // Do not want to buffer large-ish chunks
         // if the byte array is larger then MIN_CHUNK_LIMIT
         // write it directly to the output stream
         if (len > this.fragementSizeHint || len > this.buffer.capacity()) {
             // flush the buffer
-            flushBuffer();
+            flushBuffer(outputStream);
             // write directly to the out stream
-            streamWrite(b, off, len);
+            outputStream.write(b, off, len);
             this.metrics.incrementBytesTransferred(len);
         } else {
             // Do not let the buffer grow unnecessarily
             final int freecapacity = this.buffer.capacity() - this.buffer.length();
             if (len > freecapacity) {
                 // flush the buffer
-                flushBuffer();
+                flushBuffer(outputStream);
             }
             // buffer
             this.buffer.append(b, off, len);
@@ -173,23 +157,24 @@ public class SessionOutputBufferImpl imp
     }
 
     @Override
-    public void write(final byte[] b) throws IOException {
+    public void write(final byte[] b, final OutputStream outputStream) throws IOException {
         if (b == null) {
             return;
         }
-        write(b, 0, b.length);
+        write(b, 0, b.length, outputStream);
     }
 
     @Override
-    public void write(final int b) throws IOException {
+    public void write(final int b, final OutputStream outputStream) throws IOException {
+        Args.notNull(outputStream, "Output stream");
         if (this.fragementSizeHint > 0) {
             if (this.buffer.isFull()) {
-                flushBuffer();
+                flushBuffer(outputStream);
             }
             this.buffer.append(b);
         } else {
-            flushBuffer();
-            this.outstream.write(b);
+            flushBuffer(outputStream);
+            outputStream.write(b);
         }
     }
 
@@ -203,10 +188,11 @@ public class SessionOutputBufferImpl imp
      * @exception  IOException  if an I/O error occurs.
      */
     @Override
-    public void writeLine(final CharArrayBuffer charbuffer) throws IOException {
+    public void writeLine(final CharArrayBuffer charbuffer, final OutputStream outputStream) throws IOException {
         if (charbuffer == null) {
             return;
         }
+        Args.notNull(outputStream, "Output stream");
         if (this.encoder == null) {
             int off = 0;
             int remaining = charbuffer.length();
@@ -217,19 +203,19 @@ public class SessionOutputBufferImpl imp
                     this.buffer.append(charbuffer, off, chunk);
                 }
                 if (this.buffer.isFull()) {
-                    flushBuffer();
+                    flushBuffer(outputStream);
                 }
                 off += chunk;
                 remaining -= chunk;
             }
         } else {
             final CharBuffer cbuf = CharBuffer.wrap(charbuffer.buffer(), 0, charbuffer.length());
-            writeEncoded(cbuf);
+            writeEncoded(cbuf, outputStream);
         }
-        write(CRLF);
+        write(CRLF, outputStream);
     }
 
-    private void writeEncoded(final CharBuffer cbuf) throws IOException {
+    private void writeEncoded(final CharBuffer cbuf, final OutputStream outputStream) throws IOException {
         if (!cbuf.hasRemaining()) {
             return;
         }
@@ -239,20 +225,20 @@ public class SessionOutputBufferImpl imp
         this.encoder.reset();
         while (cbuf.hasRemaining()) {
             final CoderResult result = this.encoder.encode(cbuf, this.bbuf, true);
-            handleEncodingResult(result);
+            handleEncodingResult(result, outputStream);
         }
         final CoderResult result = this.encoder.flush(this.bbuf);
-        handleEncodingResult(result);
+        handleEncodingResult(result, outputStream);
         this.bbuf.clear();
     }
 
-    private void handleEncodingResult(final CoderResult result) throws IOException {
+    private void handleEncodingResult(final CoderResult result, final OutputStream outputStream) throws IOException {
         if (result.isError()) {
             result.throwException();
         }
         this.bbuf.flip();
         while (this.bbuf.hasRemaining()) {
-            write(this.bbuf.get());
+            write(this.bbuf.get(), outputStream);
         }
         this.bbuf.compact();
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentDecoder.java Mon Feb  1 16:55:59 2016
@@ -32,7 +32,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.ContentDecoder;
 import org.apache.hc.core5.http.nio.SessionInputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -48,7 +48,7 @@ public abstract class AbstractContentDec
 
     final ReadableByteChannel channel;
     final SessionInputBuffer buffer;
-    final HttpTransportMetricsImpl metrics;
+    final BasicHttpTransportMetrics metrics;
 
     boolean completed;
 
@@ -63,7 +63,7 @@ public abstract class AbstractContentDec
     public AbstractContentDecoder(
             final ReadableByteChannel channel,
             final SessionInputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         super();
         Args.notNull(channel, "Channel");
         Args.notNull(buffer, "Session input buffer");
@@ -81,7 +81,7 @@ public abstract class AbstractContentDec
         return this.buffer;
     }
 
-    protected HttpTransportMetricsImpl metrics() {
+    protected BasicHttpTransportMetrics metrics() {
         return this.metrics;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentEncoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractContentEncoder.java Mon Feb  1 16:55:59 2016
@@ -32,7 +32,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.ContentEncoder;
 import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -49,7 +49,7 @@ public abstract class AbstractContentEnc
 
     final WritableByteChannel channel;
     final SessionOutputBuffer buffer;
-    final HttpTransportMetricsImpl metrics;
+    final BasicHttpTransportMetrics metrics;
 
     boolean completed;
 
@@ -64,7 +64,7 @@ public abstract class AbstractContentEnc
     public AbstractContentEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         super();
         Args.notNull(channel, "Channel");
         Args.notNull(buffer, "Session input buffer");
@@ -82,7 +82,7 @@ public abstract class AbstractContentEnc
         return this.buffer;
     }
 
-    protected HttpTransportMetricsImpl metrics() {
+    protected BasicHttpTransportMetrics metrics() {
         return this.metrics;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java Mon Feb  1 16:55:59 2016
@@ -41,7 +41,7 @@ import org.apache.hc.core5.http.MessageC
 import org.apache.hc.core5.http.ParseException;
 import org.apache.hc.core5.http.TruncatedChunkException;
 import org.apache.hc.core5.http.config.MessageConstraints;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.message.BufferedHeader;
 import org.apache.hc.core5.http.nio.SessionInputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -80,7 +80,7 @@ public class ChunkDecoder extends Abstra
             final ReadableByteChannel channel,
             final SessionInputBuffer buffer,
             final MessageConstraints constraints,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         super(channel, buffer, metrics);
         this.state = READ_CONTENT;
         this.chunkSize = -1;
@@ -94,7 +94,7 @@ public class ChunkDecoder extends Abstra
     public ChunkDecoder(
             final ReadableByteChannel channel,
             final SessionInputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         this(channel, buffer, null, metrics);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkEncoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkEncoder.java Mon Feb  1 16:55:59 2016
@@ -35,7 +35,7 @@ import org.apache.hc.core5.annotation.No
 import org.apache.hc.core5.http.FormattedHeader;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.TrailerSupplier;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
 import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 import org.apache.hc.core5.util.CharArrayBuffer;
@@ -65,7 +65,7 @@ public class ChunkEncoder extends Abstra
     public ChunkEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final int fragementSizeHint,
             final TrailerSupplier trailers) {
         super(channel, buffer, metrics);
@@ -77,7 +77,7 @@ public class ChunkEncoder extends Abstra
     public ChunkEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         this(channel, buffer, metrics, 0, null);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityDecoder.java Mon Feb  1 16:55:59 2016
@@ -33,7 +33,7 @@ import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.FileContentDecoder;
 import org.apache.hc.core5.http.nio.SessionInputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -56,7 +56,7 @@ public class IdentityDecoder extends Abs
     public IdentityDecoder(
             final ReadableByteChannel channel,
             final SessionInputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         super(channel, buffer, metrics);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityEncoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/IdentityEncoder.java Mon Feb  1 16:55:59 2016
@@ -33,7 +33,7 @@ import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.FileContentEncoder;
 import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 
@@ -67,7 +67,7 @@ public class IdentityEncoder extends Abs
     public IdentityEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final int fragementSizeHint) {
         super(channel, buffer, metrics);
         this.fragHint = fragementSizeHint > 0 ? fragementSizeHint : 0;
@@ -76,7 +76,7 @@ public class IdentityEncoder extends Abs
     public IdentityEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics) {
+            final BasicHttpTransportMetrics metrics) {
         this(channel, buffer, metrics, 0);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java Mon Feb  1 16:55:59 2016
@@ -34,7 +34,7 @@ import java.nio.channels.ReadableByteCha
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
 import org.apache.hc.core5.http.ConnectionClosedException;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.FileContentDecoder;
 import org.apache.hc.core5.http.nio.SessionInputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -62,7 +62,7 @@ public class LengthDelimitedDecoder exte
     public LengthDelimitedDecoder(
             final ReadableByteChannel channel,
             final SessionInputBuffer buffer,
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final long contentLength) {
         super(channel, buffer, metrics);
         Args.notNegative(contentLength, "Content length");

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java?rev=1727970&r1=1727969&r2=1727970&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedEncoder.java Mon Feb  1 16:55:59 2016
@@ -33,7 +33,7 @@ import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
 
 import org.apache.hc.core5.annotation.NotThreadSafe;
-import org.apache.hc.core5.http.impl.io.HttpTransportMetricsImpl;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.nio.FileContentEncoder;
 import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 import org.apache.hc.core5.util.Args;
@@ -73,7 +73,7 @@ public class LengthDelimitedEncoder exte
     public LengthDelimitedEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final long contentLength,
             final int fragementSizeHint) {
         super(channel, buffer, metrics);
@@ -86,7 +86,7 @@ public class LengthDelimitedEncoder exte
     public LengthDelimitedEncoder(
             final WritableByteChannel channel,
             final SessionOutputBuffer buffer,
-            final HttpTransportMetricsImpl metrics,
+            final BasicHttpTransportMetrics metrics,
             final long contentLength) {
         this(channel, buffer, metrics, contentLength, 0);
     }




Mime
View raw message