You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/08/13 21:58:03 UTC

httpcomponents-core git commit: No need to hide ivar. Camel-case param names. Add missing Javadoc comments and tags.

Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x 8ffd67c9e -> c87704d12


No need to hide ivar. Camel-case param names. Add missing Javadoc
comments and tags.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/c87704d1
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/c87704d1
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/c87704d1

Branch: refs/heads/4.4.x
Commit: c87704d127d4026b5e7bb0912b3c0f5ddd442958
Parents: 8ffd67c
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 15:58:00 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Aug 13 15:58:00 2018 -0600

----------------------------------------------------------------------
 .../nio/reactor/SessionInputBufferImpl.java     | 151 +++++++++++--------
 .../nio/reactor/SessionOutputBufferImpl.java    | 118 ++++++++-------
 2 files changed, 156 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c87704d1/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
index 3cb219a..635677c 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBufferImpl.java
@@ -60,19 +60,19 @@ import org.apache.http.util.CharsetUtils;
 @SuppressWarnings("deprecation")
 public class SessionInputBufferImpl extends ExpandableBuffer implements SessionInputBuffer {
 
-    private final CharsetDecoder chardecoder;
+    private final CharsetDecoder charDecoder;
     private final MessageConstraints constraints;
-    private final int lineBuffersize;
+    private final int lineBufferSize;
 
-    private CharBuffer charbuffer;
+    private CharBuffer charBuffer;
 
     /**
      *  Creates SessionInputBufferImpl instance.
      *
-     * @param buffersize input buffer size
-     * @param lineBuffersize buffer size for line operations. Has effect only if
-     *   {@code chardecoder} is not {@code null}.
-     * @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charDecoder} is not {@code null}.
+     * @param charDecoder CharDecoder to be used for decoding HTTP protocol elements.
      *   If {@code null} simple type cast will be used for byte to char conversion.
      * @param constraints Message constraints. If {@code null}
      *   {@link MessageConstraints#DEFAULT} will be used.
@@ -82,24 +82,24 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
      * @since 4.4
      */
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final MessageConstraints constraints,
-            final CharsetDecoder chardecoder,
+            final CharsetDecoder charDecoder,
             final ByteBufferAllocator allocator) {
-        super(buffersize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
-        this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+        super(bufferSize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
+        this.lineBufferSize = Args.positive(lineBufferSize, "Line buffer size");
         this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
-        this.chardecoder = chardecoder;
+        this.charDecoder = charDecoder;
     }
 
     /**
      *  Creates SessionInputBufferImpl instance.
      *
-     * @param buffersize input buffer size
-     * @param lineBuffersize buffer size for line operations. Has effect only if
-     *   {@code chardecoder} is not {@code null}.
-     * @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charDecoder} is not {@code null}.
+     * @param charDecoder CharDecoder to be used for decoding HTTP protocol elements.
      *   If {@code null} simple type cast will be used for byte to char conversion.
      * @param allocator memory allocator.
      *   If {@code null} {@link HeapByteBufferAllocator#INSTANCE} will be used.
@@ -107,11 +107,11 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
      * @since 4.3
      */
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
-            final CharsetDecoder chardecoder,
+            final int bufferSize,
+            final int lineBufferSize,
+            final CharsetDecoder charDecoder,
             final ByteBufferAllocator allocator) {
-        this(buffersize, lineBuffersize, null, chardecoder, allocator);
+        this(bufferSize, lineBufferSize, null, charDecoder, allocator);
     }
 
     /**
@@ -121,24 +121,24 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
      */
     @Deprecated
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(buffersize, allocator);
-        this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+        super(bufferSize, allocator);
+        this.lineBufferSize = Args.positive(lineBufferSize, "Line buffer size");
         final String charsetName = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
         final Charset charset = CharsetUtils.lookup(charsetName);
         if (charset != null) {
-            this.chardecoder = charset.newDecoder();
+            this.charDecoder = charset.newDecoder();
             final CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
                     CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-            this.chardecoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
+            this.charDecoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
             final CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
                     CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-            this.chardecoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+            this.charDecoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
         } else {
-            this.chardecoder = null;
+            this.charDecoder = null;
         }
         this.constraints = MessageConstraints.DEFAULT;
     }
@@ -149,49 +149,76 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
      */
     @Deprecated
     public SessionInputBufferImpl(
-            final int buffersize,
+            final int bufferSize,
             final int linebuffersize,
             final HttpParams params) {
-        this(buffersize, linebuffersize, HeapByteBufferAllocator.INSTANCE, params);
+        this(bufferSize, linebuffersize, HeapByteBufferAllocator.INSTANCE, params);
     }
 
     /**
+     *  Creates SessionInputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charset} is not {@code null}.
+     * @param charset Charset to be used for decoding HTTP protocol elements.
+     *   If {@code null} simple type cast will be used for byte to char conversion.
+     *
      * @since 4.3
      */
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final Charset charset) {
-        this(buffersize, lineBuffersize, null,
+        this(bufferSize, lineBufferSize, null,
                 charset != null ? charset.newDecoder() : null, HeapByteBufferAllocator.INSTANCE);
     }
 
     /**
+     *  Creates SessionInputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charset} is not {@code null}.
+     * @param charset Charset to be used for decoding HTTP protocol elements.
+     *   If {@code null} simple type cast will be used for byte to char conversion.
+     * @param constraints Message constraints. If {@code null}
+     *   {@link MessageConstraints#DEFAULT} will be used.
+     *
      * @since 4.3
      */
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final MessageConstraints constraints,
             final Charset charset) {
-        this(buffersize, lineBuffersize, constraints,
+        this(bufferSize, lineBufferSize, constraints,
                 charset != null ? charset.newDecoder() : null, HeapByteBufferAllocator.INSTANCE);
     }
 
     /**
+     *  Creates SessionInputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations.
+     *
      * @since 4.3
      */
     public SessionInputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize) {
-        this(buffersize, lineBuffersize, null, null, HeapByteBufferAllocator.INSTANCE);
+            final int bufferSize,
+            final int lineBufferSize) {
+        this(bufferSize, lineBufferSize, null, null, HeapByteBufferAllocator.INSTANCE);
     }
 
     /**
+     *  Creates SessionInputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     *
      * @since 4.3
      */
-    public SessionInputBufferImpl(final int buffersize) {
-        this(buffersize, 256, null, null, HeapByteBufferAllocator.INSTANCE);
+    public SessionInputBufferImpl(final int bufferSize) {
+        this(bufferSize, 256, null, null, HeapByteBufferAllocator.INSTANCE);
     }
 
     @Override
@@ -307,7 +334,7 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
         // Ensure capacity of len assuming ASCII as the most likely charset
         linebuffer.ensureCapacity(requiredCapacity);
 
-        if (this.chardecoder == null) {
+        if (this.charDecoder == null) {
             if (this.buffer.hasArray()) {
                 final byte[] b = this.buffer.array();
                 final int off = this.buffer.position();
@@ -320,26 +347,26 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
                 }
             }
         } else {
-            if (this.charbuffer == null) {
-                this.charbuffer = CharBuffer.allocate(this.lineBuffersize);
+            if (this.charBuffer == null) {
+                this.charBuffer = CharBuffer.allocate(this.lineBufferSize);
             }
-            this.chardecoder.reset();
+            this.charDecoder.reset();
 
             for (;;) {
-                final CoderResult result = this.chardecoder.decode(
+                final CoderResult result = this.charDecoder.decode(
                         this.buffer,
-                        this.charbuffer,
+                        this.charBuffer,
                         true);
                 if (result.isError()) {
                     result.throwException();
                 }
                 if (result.isOverflow()) {
-                    this.charbuffer.flip();
+                    this.charBuffer.flip();
                     linebuffer.append(
-                            this.charbuffer.array(),
-                            this.charbuffer.position(),
-                            this.charbuffer.remaining());
-                    this.charbuffer.clear();
+                            this.charBuffer.array(),
+                            this.charBuffer.position(),
+                            this.charBuffer.remaining());
+                    this.charBuffer.clear();
                 }
                 if (result.isUnderflow()) {
                     break;
@@ -347,14 +374,14 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
             }
 
             // flush the decoder
-            this.chardecoder.flush(this.charbuffer);
-            this.charbuffer.flip();
+            this.charDecoder.flush(this.charBuffer);
+            this.charBuffer.flip();
             // append the decoded content to the line buffer
-            if (this.charbuffer.hasRemaining()) {
+            if (this.charBuffer.hasRemaining()) {
                 linebuffer.append(
-                        this.charbuffer.array(),
-                        this.charbuffer.position(),
-                        this.charbuffer.remaining());
+                        this.charBuffer.array(),
+                        this.charBuffer.position(),
+                        this.charBuffer.remaining());
             }
 
         }
@@ -380,9 +407,9 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
 
     @Override
     public String readLine(final boolean endOfStream) throws CharacterCodingException {
-        final CharArrayBuffer buffer = new CharArrayBuffer(64);
-        final boolean found = readLine(buffer, endOfStream);
-        return found ? buffer.toString() : null;
+        final CharArrayBuffer tmpBuffer = new CharArrayBuffer(64);
+        final boolean found = readLine(tmpBuffer, endOfStream);
+        return found ? tmpBuffer.toString() : null;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c87704d1/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
index 73f063b..1114538 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBufferImpl.java
@@ -60,18 +60,18 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
 
-    private final CharsetEncoder charencoder;
-    private final int lineBuffersize;
+    private final CharsetEncoder charEncoder;
+    private final int lineBufferSize;
 
-    private CharBuffer charbuffer;
+    private CharBuffer charBuffer;
 
     /**
      *  Creates SessionOutputBufferImpl instance.
      *
-     * @param buffersize input buffer size
-     * @param lineBuffersize buffer size for line operations. Has effect only if
-     *   {@code charencoder} is not {@code null}.
-     * @param charencoder charencoder to be used for encoding HTTP protocol elements.
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charEncoder} is not {@code null}.
+     * @param charEncoder CharEncoder to be used for encoding HTTP protocol elements.
      *   If {@code null} simple type cast will be used for char to byte conversion.
      * @param allocator memory allocator.
      *   If {@code null} {@link HeapByteBufferAllocator#INSTANCE} will be used.
@@ -79,13 +79,13 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
      * @since 4.3
      */
     public SessionOutputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
-            final CharsetEncoder charencoder,
+            final int bufferSize,
+            final int lineBufferSize,
+            final CharsetEncoder charEncoder,
             final ByteBufferAllocator allocator) {
-        super(buffersize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
-        this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
-        this.charencoder = charencoder;
+        super(bufferSize, allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE);
+        this.lineBufferSize = Args.positive(lineBufferSize, "Line buffer size");
+        this.charEncoder = charEncoder;
     }
 
     /**
@@ -95,24 +95,24 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
      */
     @Deprecated
     public SessionOutputBufferImpl(
-            final int buffersize,
-            final int lineBuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(buffersize, allocator);
-        this.lineBuffersize = Args.positive(lineBuffersize, "Line buffer size");
+        super(bufferSize, allocator);
+        this.lineBufferSize = Args.positive(lineBufferSize, "Line buffer size");
         final String charsetName = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
         final Charset charset = CharsetUtils.lookup(charsetName);
         if (charset != null) {
-            this.charencoder = charset.newEncoder();
+            this.charEncoder = charset.newEncoder();
             final CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
                     CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
-            this.charencoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
+            this.charEncoder.onMalformedInput(a1 != null ? a1 : CodingErrorAction.REPORT);
             final CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
                     CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
-            this.charencoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
+            this.charEncoder.onUnmappableCharacter(a2 != null? a2 : CodingErrorAction.REPORT);
         } else {
-            this.charencoder = null;
+            this.charEncoder = null;
         }
     }
 
@@ -122,37 +122,53 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
      */
     @Deprecated
     public SessionOutputBufferImpl(
-            final int buffersize,
-            final int linebuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final HttpParams params) {
-        this(buffersize, linebuffersize, HeapByteBufferAllocator.INSTANCE, params);
+        this(bufferSize, lineBufferSize, HeapByteBufferAllocator.INSTANCE, params);
     }
 
     /**
+     *  Creates SessionOutputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
      * @since 4.3
      */
-    public SessionOutputBufferImpl(final int buffersize) {
-        this(buffersize, 256, null, HeapByteBufferAllocator.INSTANCE);
+    public SessionOutputBufferImpl(final int bufferSize) {
+        this(bufferSize, 256, null, HeapByteBufferAllocator.INSTANCE);
     }
 
     /**
+     *  Creates SessionOutputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations. Has effect only if
+     *   {@code charset} is not {@code null}.
+     * @param charset Charset to be used for encoding HTTP protocol elements.
+     *   If {@code null} simple type cast will be used for char to byte conversion.
+     *
      * @since 4.3
      */
     public SessionOutputBufferImpl(
-            final int buffersize,
-            final int linebuffersize,
+            final int bufferSize,
+            final int lineBufferSize,
             final Charset charset) {
-        this(buffersize, linebuffersize,
+        this(bufferSize, lineBufferSize,
                 charset != null ? charset.newEncoder() : null, HeapByteBufferAllocator.INSTANCE);
     }
 
     /**
+     *  Creates SessionOutputBufferImpl instance.
+     *
+     * @param bufferSize input buffer size.
+     * @param lineBufferSize buffer size for line operations.
+     *
      * @since 4.3
      */
     public SessionOutputBufferImpl(
-            final int buffersize,
-            final int linebuffersize) {
-        this(buffersize, linebuffersize, null, HeapByteBufferAllocator.INSTANCE);
+            final int bufferSize,
+            final int lineBufferSize) {
+        this(bufferSize, lineBufferSize, null, HeapByteBufferAllocator.INSTANCE);
     }
 
     public void reset(final HttpParams params) {
@@ -203,51 +219,51 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
     }
 
     @Override
-    public void writeLine(final CharArrayBuffer linebuffer) throws CharacterCodingException {
-        if (linebuffer == null) {
+    public void writeLine(final CharArrayBuffer lineBuffer) throws CharacterCodingException {
+        if (lineBuffer == null) {
             return;
         }
         setInputMode();
         // Do not bother if the buffer is empty
-        if (linebuffer.length() > 0 ) {
-            if (this.charencoder == null) {
-                final int requiredCapacity = this.buffer.position() + linebuffer.length();
+        if (lineBuffer.length() > 0 ) {
+            if (this.charEncoder == null) {
+                final int requiredCapacity = this.buffer.position() + lineBuffer.length();
                 ensureCapacity(requiredCapacity);
                 if (this.buffer.hasArray()) {
                     final byte[] b = this.buffer.array();
-                    final int len = linebuffer.length();
+                    final int len = lineBuffer.length();
                     final int off = this.buffer.position();
                     for (int i = 0; i < len; i++) {
-                        b[off + i]  = (byte) linebuffer.charAt(i);
+                        b[off + i]  = (byte) lineBuffer.charAt(i);
                     }
                     this.buffer.position(off + len);
                 } else {
-                    for (int i = 0; i < linebuffer.length(); i++) {
-                        this.buffer.put((byte) linebuffer.charAt(i));
+                    for (int i = 0; i < lineBuffer.length(); i++) {
+                        this.buffer.put((byte) lineBuffer.charAt(i));
                     }
                 }
             } else {
-                if (this.charbuffer == null) {
-                    this.charbuffer = CharBuffer.allocate(this.lineBuffersize);
+                if (this.charBuffer == null) {
+                    this.charBuffer = CharBuffer.allocate(this.lineBufferSize);
                 }
-                this.charencoder.reset();
+                this.charEncoder.reset();
                 // transfer the string in small chunks
-                int remaining = linebuffer.length();
+                int remaining = lineBuffer.length();
                 int offset = 0;
                 while (remaining > 0) {
-                    int l = this.charbuffer.remaining();
+                    int l = this.charBuffer.remaining();
                     boolean eol = false;
                     if (remaining <= l) {
                         l = remaining;
                         // terminate the encoding process
                         eol = true;
                     }
-                    this.charbuffer.put(linebuffer.buffer(), offset, l);
-                    this.charbuffer.flip();
+                    this.charBuffer.put(lineBuffer.buffer(), offset, l);
+                    this.charBuffer.flip();
 
                     boolean retry = true;
                     while (retry) {
-                        final CoderResult result = this.charencoder.encode(this.charbuffer, this.buffer, eol);
+                        final CoderResult result = this.charEncoder.encode(this.charBuffer, this.buffer, eol);
                         if (result.isError()) {
                             result.throwException();
                         }
@@ -256,14 +272,14 @@ public class SessionOutputBufferImpl extends ExpandableBuffer implements Session
                         }
                         retry = !result.isUnderflow();
                     }
-                    this.charbuffer.compact();
+                    this.charBuffer.compact();
                     offset += l;
                     remaining -= l;
                 }
                 // flush the encoder
                 boolean retry = true;
                 while (retry) {
-                    final CoderResult result = this.charencoder.flush(this.buffer);
+                    final CoderResult result = this.charEncoder.flush(this.buffer);
                     if (result.isError()) {
                         result.throwException();
                     }