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 2020/11/23 23:47:35 UTC

[httpcomponents-core] branch master updated (f674d69 -> 01ed03a)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


    from f674d69  Updated Docker images and external compatibility tests
     new 471abe8  Use try-with-resources.
     new ea907c5  Use diamonds.
     new c610ad8  Add missing @Override.
     new e78efb6  Make better use of Map APIs.
     new 6c7bbb6  Remove redundant modifiers.
     new 757bb7f  Use Collections.addAll() API instead of loops.
     new 01ed03a  Remote extra semicolons (;).

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../hc/core5/http2/examples/H2GreetingServer.java  |  2 +-
 .../org/apache/hc/core5/testing/SocksProxy.java    |  2 +-
 .../http/io/support/TerminalServerFilter.java      |  2 +-
 .../apache/hc/core5/http/message/TokenParser.java  |  3 ++
 .../core5/http/nio/entity/NoopEntityConsumer.java  |  6 ++--
 .../nio/support/BasicClientExchangeHandler.java    |  4 +--
 .../support/ImmediateResponseExchangeHandler.java  |  8 ++---
 .../apache/hc/core5/http/protocol/HttpContext.java |  2 +-
 .../java/org/apache/hc/core5/net/URIBuilder.java   |  4 +--
 .../java/org/apache/hc/core5/pool/LaxConnPool.java |  2 +-
 .../hc/core5/reactor/EndpointParameters.java       |  1 +
 .../org/apache/hc/core5/reactor/IOSession.java     |  2 ++
 .../hc/core5/reactor/SingleCoreIOReactor.java      |  2 +-
 .../core5/reactor/SocksProxyProtocolHandler.java   |  2 +-
 .../org/apache/hc/core5/ssl/SSLContextBuilder.java |  9 ++---
 .../hc/core5/http/impl/nio/CodecTestUtils.java     |  5 +--
 .../core5/http/impl/nio/TestIdentityDecoder.java   | 20 +++--------
 .../http/impl/nio/TestLengthDelimitedDecoder.java  | 30 ++++------------
 .../hc/core5/http/message/TestMessageSupport.java  |  5 ++-
 .../apache/hc/core5/ssl/TestSSLContextBuilder.java | 42 +++++-----------------
 20 files changed, 48 insertions(+), 105 deletions(-)


[httpcomponents-core] 02/07: Use diamonds.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit ea907c5e79b2d90008953c14631a6364db1b27ff
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 10:49:09 2020 -0500

    Use diamonds.
---
 .../test/java/org/apache/hc/core5/http2/examples/H2GreetingServer.java  | 2 +-
 .../src/main/java/org/apache/hc/core5/testing/SocksProxy.java           | 2 +-
 httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2GreetingServer.java b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2GreetingServer.java
index 551be6f..8e1c65c 100644
--- a/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2GreetingServer.java
+++ b/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2GreetingServer.java
@@ -137,7 +137,7 @@ public class H2GreetingServer {
                 entityConsumer = new StringAsyncEntityConsumer();
             }
             //noinspection unchecked
-            return new BasicRequestConsumer<String>(entityConsumer);
+            return new BasicRequestConsumer<>(entityConsumer);
 
         }
 
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/SocksProxy.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/SocksProxy.java
index 2ddce4f..40a17a3 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/SocksProxy.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/SocksProxy.java
@@ -210,7 +210,7 @@ public class SocksProxy {
 
     private final int port;
 
-    private final List<SocksProxyHandler> handlers = new ArrayList<SocksProxyHandler>();
+    private final List<SocksProxyHandler> handlers = new ArrayList<>();
     private ServerSocket server;
     private Thread serverThread;
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
index 82d2119..26b56e6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
@@ -419,7 +419,7 @@ public class LaxConnPool<T, C extends ModalCloseable> implements ManagedConnPool
                 prev = allocated.get();
                 next = (prev<poolmax)? prev+1 : prev;
             } while (!allocated.compareAndSet(prev, next));
-            return (prev < next)? new PoolEntry<T,C>(route, timeToLive, disposalCallback) : null;
+            return (prev < next)? new PoolEntry<>(route, timeToLive, disposalCallback) : null;
         }
 
         private void deallocatePoolEntry() {


[httpcomponents-core] 05/07: Remove redundant modifiers.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 6c7bbb6f1da60d69321aa79d8cad7e756af0dbd7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 11:43:16 2020 -0500

    Remove redundant modifiers.
    
    - All methods in a final class are already final.
    - All members of an interface are public.
    - All inner enums are static.
---
 .../org/apache/hc/core5/http/io/support/TerminalServerFilter.java | 2 +-
 .../org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java   | 6 +++---
 .../hc/core5/http/nio/support/BasicClientExchangeHandler.java     | 4 ++--
 .../core5/http/nio/support/ImmediateResponseExchangeHandler.java  | 8 ++++----
 .../main/java/org/apache/hc/core5/http/protocol/HttpContext.java  | 2 +-
 .../org/apache/hc/core5/reactor/SocksProxyProtocolHandler.java    | 2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/support/TerminalServerFilter.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/support/TerminalServerFilter.java
index 5955f68..b10e21a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/support/TerminalServerFilter.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/support/TerminalServerFilter.java
@@ -64,7 +64,7 @@ public final class TerminalServerFilter implements HttpFilterHandler {
     }
 
     @Override
-    public final void handle(
+    public void handle(
             final ClassicHttpRequest request,
             final HttpFilterChain.ResponseTrigger responseTrigger,
             final HttpContext context,
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
index b2188f1..d3132f9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
@@ -47,7 +47,7 @@ public final class NoopEntityConsumer implements AsyncEntityConsumer<Void> {
     private volatile FutureCallback<Void> resultCallback;
 
     @Override
-    public final void streamStart(
+    public void streamStart(
             final EntityDetails entityDetails,
             final FutureCallback<Void> resultCallback) throws IOException, HttpException {
         this.resultCallback = resultCallback;
@@ -59,11 +59,11 @@ public final class NoopEntityConsumer implements AsyncEntityConsumer<Void> {
     }
 
     @Override
-    public final void consume(final ByteBuffer src) throws IOException {
+    public void consume(final ByteBuffer src) throws IOException {
     }
 
     @Override
-    public final void streamEnd(final List<? extends Header> trailers) throws IOException {
+    public void streamEnd(final List<? extends Header> trailers) throws IOException {
         if (resultCallback != null) {
             resultCallback.completed(null);
         }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
index 0cf0f7a..3296afc 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
@@ -175,7 +175,7 @@ public final class BasicClientExchangeHandler<T> implements AsyncClientExchangeH
     }
 
     @Override
-    public final void failed(final Exception cause) {
+    public void failed(final Exception cause) {
         try {
             requestProducer.failed(cause);
             responseConsumer.failed(cause);
@@ -198,7 +198,7 @@ public final class BasicClientExchangeHandler<T> implements AsyncClientExchangeH
     }
 
     @Override
-    public final void releaseResources() {
+    public void releaseResources() {
     }
 
 }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/ImmediateResponseExchangeHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/ImmediateResponseExchangeHandler.java
index cc5e214..d165451 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/ImmediateResponseExchangeHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/ImmediateResponseExchangeHandler.java
@@ -91,23 +91,23 @@ public final class ImmediateResponseExchangeHandler implements AsyncServerExchan
     }
 
     @Override
-    public final int available() {
+    public int available() {
         return responseProducer.available();
     }
 
     @Override
-    public final void produce(final DataStreamChannel channel) throws IOException {
+    public void produce(final DataStreamChannel channel) throws IOException {
         responseProducer.produce(channel);
     }
 
     @Override
-    public final void failed(final Exception cause) {
+    public void failed(final Exception cause) {
         responseProducer.failed(cause);
         releaseResources();
     }
 
     @Override
-    public final void releaseResources() {
+    public void releaseResources() {
         responseProducer.releaseResources();
     }
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpContext.java b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpContext.java
index c0e0651..0d7db11 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpContext.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/HttpContext.java
@@ -50,7 +50,7 @@ import org.apache.hc.core5.http.ProtocolVersion;
 public interface HttpContext {
 
     /** The prefix reserved for use by HTTP components. "http." */
-    public static final String RESERVED_PREFIX  = "http.";
+    String RESERVED_PREFIX  = "http.";
 
     /**
      * Returns protocol version used in this context.
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SocksProxyProtocolHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SocksProxyProtocolHandler.java
index 73fd246..9d3e72e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SocksProxyProtocolHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SocksProxyProtocolHandler.java
@@ -70,7 +70,7 @@ final class SocksProxyProtocolHandler implements IOEventHandler {
 
     private static final byte ATYP_IPV6 = 4;
 
-    private static enum State {
+    private enum State {
         SEND_AUTH, RECEIVE_AUTH_METHOD, SEND_USERNAME_PASSWORD, RECEIVE_AUTH, SEND_CONNECT, RECEIVE_RESPONSE_CODE, RECEIVE_ADDRESS_TYPE, RECEIVE_ADDRESS, COMPLETE
     }
 


[httpcomponents-core] 04/07: Make better use of Map APIs.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit e78efb66c2255fa6640f3115bb5a3d35519bd89d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 11:36:22 2020 -0500

    Make better use of Map APIs.
---
 .../src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
index 5ce874d..bc36248 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
@@ -545,7 +545,7 @@ public class TestSSLContextBuilder {
             @Override
             public String chooseAlias(final Map<String, PrivateKeyDetails> aliases,
                             final SSLParameters sslParameters) {
-                return aliases.keySet().contains("client2") ? "client2" : null;
+                return aliases.containsKey("client2") ? "client2" : null;
             }
         };
 


[httpcomponents-core] 03/07: Add missing @Override.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit c610ad89079dd7c54235f81c943a1c473583cf26
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 11:13:31 2020 -0500

    Add missing @Override.
---
 .../src/main/java/org/apache/hc/core5/http/message/TokenParser.java    | 3 +++
 .../src/main/java/org/apache/hc/core5/reactor/EndpointParameters.java  | 1 +
 httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java     | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/TokenParser.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/TokenParser.java
index 24c058d..94e5887 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/TokenParser.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/TokenParser.java
@@ -72,6 +72,7 @@ public class TokenParser extends Tokenizer {
         super.copyContent(buf, cursor, delimiters, dst);
     }
 
+    @Override
     public void copyContent(final CharSequence buf, final Tokenizer.Cursor cursor, final BitSet delimiters,
                             final StringBuilder dst) {
         final ParserCursor parserCursor = new ParserCursor(cursor.getLowerBound(), cursor.getUpperBound());
@@ -85,6 +86,7 @@ public class TokenParser extends Tokenizer {
         super.copyUnquotedContent(buf, cursor, delimiters, dst);
     }
 
+    @Override
     public void copyUnquotedContent(final CharSequence buf, final Tokenizer.Cursor cursor, final BitSet delimiters,
                                     final StringBuilder dst) {
         final ParserCursor parserCursor = new ParserCursor(cursor.getLowerBound(), cursor.getUpperBound());
@@ -97,6 +99,7 @@ public class TokenParser extends Tokenizer {
         super.copyQuotedContent(buf, cursor, dst);
     }
 
+    @Override
     public void copyQuotedContent(final CharSequence buf, final Tokenizer.Cursor cursor, final StringBuilder dst) {
         final ParserCursor parserCursor = new ParserCursor(cursor.getLowerBound(), cursor.getUpperBound());
         parserCursor.updatePos(cursor.getPos());
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/EndpointParameters.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/EndpointParameters.java
index a2b2f37..bd5a434 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/EndpointParameters.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/EndpointParameters.java
@@ -64,6 +64,7 @@ public final class EndpointParameters implements NamedEndpoint {
         return scheme;
     }
 
+    @Override
     public String getHostName() {
         return hostName;
     }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
index 2985704..fd3813f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
@@ -189,6 +189,7 @@ public interface IOSession extends ByteChannel, SocketModalCloseable, Identifiab
      *
      * @return socket timeout.
      */
+    @Override
     Timeout getSocketTimeout();
 
     /**
@@ -201,6 +202,7 @@ public interface IOSession extends ByteChannel, SocketModalCloseable, Identifiab
      *
      * @param timeout socket timeout.
      */
+    @Override
     void setSocketTimeout(Timeout timeout);
 
     /**


[httpcomponents-core] 01/07: Use try-with-resources.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 471abe8fb08bb3fb98fcbb1013d7255ea29855ce
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 10:42:13 2020 -0500

    Use try-with-resources.
---
 .../hc/core5/http/impl/nio/CodecTestUtils.java     |  5 +--
 .../core5/http/impl/nio/TestIdentityDecoder.java   | 20 +++--------
 .../http/impl/nio/TestLengthDelimitedDecoder.java  | 30 ++++------------
 .../apache/hc/core5/ssl/TestSSLContextBuilder.java | 40 +++++-----------------
 4 files changed, 19 insertions(+), 76 deletions(-)

diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/CodecTestUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/CodecTestUtils.java
index 8128ce0..155a00f 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/CodecTestUtils.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/CodecTestUtils.java
@@ -50,8 +50,7 @@ class CodecTestUtils {
 
     public static String readFromFile(final File file) throws Exception {
         final FileInputStream filestream = new FileInputStream(file);
-        final InputStreamReader reader = new InputStreamReader(filestream);
-        try {
+        try (InputStreamReader reader = new InputStreamReader(filestream)) {
             final StringBuilder buffer = new StringBuilder();
             final char[] tmp = new char[2048];
             int l;
@@ -59,8 +58,6 @@ class CodecTestUtils {
                 buffer.append(tmp, 0, l);
             }
             return buffer.toString();
-        } finally {
-            reader.close();
         }
     }
 
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityDecoder.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityDecoder.java
index 0df1f1d..40c81ec 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityDecoder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityDecoder.java
@@ -154,8 +154,7 @@ public class TestIdentityDecoder {
                 channel, inbuf, metrics);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
             while (!decoder.isCompleted()) {
@@ -166,8 +165,6 @@ public class TestIdentityDecoder {
             }
 
             Assert.assertEquals(testfile.length(), metrics.getBytesTransferred());
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
             CodecTestUtils.readFromFile(this.tmpfile));
@@ -187,8 +184,7 @@ public class TestIdentityDecoder {
         Assert.assertEquals(7, i);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
             while (!decoder.isCompleted()) {
@@ -200,8 +196,6 @@ public class TestIdentityDecoder {
 
             // count everything except the initial 7 bytes that went to the session buffer
             Assert.assertEquals(testfile.length() - 7, metrics.getBytesTransferred());
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
             CodecTestUtils.readFromFile(this.tmpfile));
@@ -267,8 +261,7 @@ public class TestIdentityDecoder {
         Assert.assertEquals(19, i);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
 
@@ -314,8 +307,6 @@ public class TestIdentityDecoder {
             Assert.assertEquals(-1, bytesRead);
             Assert.assertTrue(decoder.isCompleted());
             Assert.assertEquals(17, metrics.getBytesTransferred());
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
                 CodecTestUtils.readFromFile(this.tmpfile));
@@ -332,16 +323,13 @@ public class TestIdentityDecoder {
                 channel, inbuf, metrics);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             Assert.assertEquals(0, testfile.length());
             final FileChannel fchannel = testfile.getChannel();
             try {
                 decoder.transfer(fchannel, 5, 10);
                 Assert.fail("expected IOException");
             } catch(final IOException iox) {}
-        } finally {
-            testfile.close();
         }
     }
 
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedDecoder.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedDecoder.java
index 4ab31d4..a455ff5 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedDecoder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedDecoder.java
@@ -265,8 +265,7 @@ public class TestLengthDelimitedDecoder {
                 channel, inbuf, metrics, 36);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
             while (!decoder.isCompleted()) {
@@ -275,8 +274,6 @@ public class TestLengthDelimitedDecoder {
                     pos += bytesRead;
                 }
             }
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals(this.tmpfile.length(), metrics.getBytesTransferred());
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
@@ -297,8 +294,7 @@ public class TestLengthDelimitedDecoder {
         Assert.assertEquals(7, i);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
             while (!decoder.isCompleted()) {
@@ -307,8 +303,6 @@ public class TestLengthDelimitedDecoder {
                     pos += bytesRead;
                 }
             }
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals(this.tmpfile.length() - 7, metrics.getBytesTransferred());
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
@@ -375,8 +369,7 @@ public class TestLengthDelimitedDecoder {
         Assert.assertEquals(19, i);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             long pos = 0;
 
@@ -422,8 +415,6 @@ public class TestLengthDelimitedDecoder {
             Assert.assertEquals(-1, bytesRead);
             Assert.assertTrue(decoder.isCompleted());
             Assert.assertEquals(17, metrics.getBytesTransferred());
-        } finally {
-            testfile.close();
         }
         Assert.assertEquals("stuff; more stuff; a lot more stuff!",
                 CodecTestUtils.readFromFile(this.tmpfile));
@@ -440,8 +431,7 @@ public class TestLengthDelimitedDecoder {
                 channel, inbuf, metrics, 1);
 
         createTempFile();
-        final RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             Assert.assertEquals(0, testfile.length());
             try {
@@ -449,8 +439,6 @@ public class TestLengthDelimitedDecoder {
                 Assert.fail("IOException should have been thrown");
             } catch(final IOException expected) {
             }
-        } finally {
-            testfile.close();
         }
     }
 
@@ -467,8 +455,7 @@ public class TestLengthDelimitedDecoder {
                 channel, inbuf, metrics, 16);
 
         createTempFile();
-        final RandomAccessFile testfile  = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile  = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
 
             long bytesRead = decoder.transfer(fchannel, 0, 6);
@@ -485,8 +472,6 @@ public class TestLengthDelimitedDecoder {
             Assert.assertEquals(-1, bytesRead);
             Assert.assertTrue(decoder.isCompleted());
             Assert.assertEquals(16, metrics.getBytesTransferred());
-        } finally {
-            testfile.close();
         }
     }
 
@@ -588,14 +573,11 @@ public class TestLengthDelimitedDecoder {
                 channel, inbuf, metrics, 20);
 
         createTempFile();
-        final RandomAccessFile testfile  = new RandomAccessFile(this.tmpfile, "rw");
-        try {
+        try (RandomAccessFile testfile  = new RandomAccessFile(this.tmpfile, "rw")) {
             final FileChannel fchannel = testfile.getChannel();
             final long bytesRead = decoder.transfer(fchannel, 0, Integer.MAX_VALUE);
             Assert.assertEquals(10, bytesRead);
             decoder.transfer(fchannel, 0, Integer.MAX_VALUE);
-        } finally {
-            testfile.close();
         }
     }
 
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
index ee0e369..5ce874d 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
@@ -249,13 +249,10 @@ public class TestSSLContextBuilder {
         final Future<Boolean> future = this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final Socket socket = serverSocket.accept();
-                try {
+                try (Socket socket = serverSocket.accept()) {
                     final OutputStream outputStream = socket.getOutputStream();
                     outputStream.write(new byte[]{'H', 'i'});
                     outputStream.flush();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.TRUE;
             }
@@ -298,11 +295,8 @@ public class TestSSLContextBuilder {
         this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     socket.getSession();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.FALSE;
             }
@@ -350,13 +344,10 @@ public class TestSSLContextBuilder {
         final Future<Boolean> future = this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final Socket socket = serverSocket.accept();
-                try {
+                try (Socket socket = serverSocket.accept()) {
                     final OutputStream outputStream = socket.getOutputStream();
                     outputStream.write(new byte[]{'H', 'i'});
                     outputStream.flush();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.TRUE;
             }
@@ -473,11 +464,8 @@ public class TestSSLContextBuilder {
         this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     socket.getSession();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.FALSE;
             }
@@ -517,16 +505,13 @@ public class TestSSLContextBuilder {
         final Future<Principal> future = this.executorService.submit(new Callable<Principal>() {
             @Override
             public Principal call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     final SSLSession session = socket.getSession();
                     final Principal clientPrincipal = session.getPeerPrincipal();
                     final OutputStream outputStream = socket.getOutputStream();
                     outputStream.write(new byte[]{'H', 'i'});
                     outputStream.flush();
                     return clientPrincipal;
-                } finally {
-                    socket.close();
                 }
             }
         });
@@ -578,16 +563,13 @@ public class TestSSLContextBuilder {
         final Future<Principal> future = this.executorService.submit(new Callable<Principal>() {
             @Override
             public Principal call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     final SSLSession session = socket.getSession();
                     final Principal clientPrincipal = session.getPeerPrincipal();
                     final OutputStream outputStream = socket.getOutputStream();
                     outputStream.write(new byte[]{'H', 'i'});
                     outputStream.flush();
                     return clientPrincipal;
-                } finally {
-                    socket.close();
                 }
             }
         });
@@ -638,11 +620,8 @@ public class TestSSLContextBuilder {
         this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     socket.getSession();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.FALSE;
             }
@@ -689,11 +668,8 @@ public class TestSSLContextBuilder {
         this.executorService.submit(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                final SSLSocket socket = (SSLSocket) serverSocket.accept();
-                try {
+                try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
                     socket.getSession();
-                } finally {
-                    socket.close();
                 }
                 return Boolean.FALSE;
             }


[httpcomponents-core] 06/07: Use Collections.addAll() API instead of loops.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 757bb7f7f803dad52b5e4e5c9bf3a9f299ddd87e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 12:06:09 2020 -0500

    Use Collections.addAll() API instead of loops.
---
 httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java  | 4 +---
 .../src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java | 9 +++------
 .../org/apache/hc/core5/http/message/TestMessageSupport.java     | 5 ++---
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
index c8f3fa7..89768e9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
@@ -630,9 +630,7 @@ public class URIBuilder {
         } else {
             this.queryParams.clear();
         }
-        for (final NameValuePair nvp: nvps) {
-            this.queryParams.add(nvp);
-        }
+        Collections.addAll(this.queryParams, nvps);
         this.encodedQuery = null;
         this.encodedSchemeSpecificPart = null;
         this.query = null;
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index 89ecac2..1a2b69d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -46,6 +46,7 @@ import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
@@ -210,9 +211,7 @@ public class SSLContextBuilder {
                     }
                 }
             }
-            for (final TrustManager tm : tms) {
-                this.trustManagers.add(tm);
-            }
+            Collections.addAll(this.trustManagers, tms);
         }
         return this;
     }
@@ -282,9 +281,7 @@ public class SSLContextBuilder {
                     }
                 }
             }
-            for (final KeyManager km : kms) {
-                keyManagers.add(km);
-            }
+            Collections.addAll(keyManagers, kms);
         }
         return this;
     }
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestMessageSupport.java b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestMessageSupport.java
index cf80a4d..5426c70 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestMessageSupport.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestMessageSupport.java
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.message;
 
 import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
@@ -47,9 +48,7 @@ public class TestMessageSupport {
             return null;
         }
         final Set<String> set = new LinkedHashSet<>();
-        for (final String token: tokens) {
-            set.add(token);
-        }
+        Collections.addAll(set, tokens);
         return set;
     }
 


[httpcomponents-core] 07/07: Remote extra semicolons (;).

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 01ed03a7e2a85155a2d7eab3b518ebc3ebdba3dc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 23 12:35:03 2020 -0500

    Remote extra semicolons (;).
---
 .../src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
index 269c8a7..ec80a0f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
@@ -345,7 +345,7 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements Connect
                             @Override
                             public Boolean run() throws IOException {
                                 return socketChannel.connect(targetAddress);
-                            };
+                            }
                         });
         } catch (final PrivilegedActionException e) {
             Asserts.check(e.getCause() instanceof  IOException,