diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index c120fa77c..3e81b1def 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -252,16 +252,16 @@ public class URIUtils { } String[] inputSegments = path.split("/"); Stack outputSegments = new Stack(); - for (int i = 0; i < inputSegments.length; i++) { - if ((inputSegments[i].length() == 0) - || (".".equals(inputSegments[i]))) { + for (String inputSegment : inputSegments) { + if ((inputSegment.length() == 0) + || (".".equals(inputSegment))) { // Do nothing - } else if ("..".equals(inputSegments[i])) { + } else if ("..".equals(inputSegment)) { if (!outputSegments.isEmpty()) { outputSegments.pop(); } } else { - outputSegments.push(inputSegments[i]); + outputSegments.push(inputSegment); } } StringBuilder outputBuffer = new StringBuilder(); diff --git a/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java b/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java index 511f424a1..b70b03a6b 100644 --- a/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java +++ b/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java @@ -358,8 +358,8 @@ public final class HttpRoute implements RouteInfo, Cloneable { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.targetHost); hash = LangUtils.hashCode(hash, this.localAddress); - for (int i = 0; i < this.proxyChain.length; i++) { - hash = LangUtils.hashCode(hash, this.proxyChain[i]); + for (HttpHost element : this.proxyChain) { + hash = LangUtils.hashCode(hash, element); } hash = LangUtils.hashCode(hash, this.secure); hash = LangUtils.hashCode(hash, this.tunnelled); diff --git a/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java b/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java index ee9f324b0..d8226bbe1 100644 --- a/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java +++ b/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java @@ -329,8 +329,8 @@ public final class RouteTracker implements RouteInfo, Cloneable { hash = LangUtils.hashCode(hash, this.targetHost); hash = LangUtils.hashCode(hash, this.localAddress); if (this.proxyChain != null) { - for (int i = 0; i < this.proxyChain.length; i++) { - hash = LangUtils.hashCode(hash, this.proxyChain[i]); + for (HttpHost element : this.proxyChain) { + hash = LangUtils.hashCode(hash, element); } } hash = LangUtils.hashCode(hash, this.connected); @@ -365,8 +365,8 @@ public final class RouteTracker implements RouteInfo, Cloneable { cab.append('s'); cab.append("}->"); if (this.proxyChain != null) { - for (int i=0; i"); } } diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java b/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java index 3251f25d9..c0a4bd679 100644 --- a/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java +++ b/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java @@ -709,8 +709,8 @@ final class NTLMEngineImpl implements NTLMEngine { * the bytes to add. */ protected void addBytes(byte[] bytes) { - for (int i = 0; i < bytes.length; i++) { - messageContents[currentOutputPosition] = bytes[i]; + for (byte b : bytes) { + messageContents[currentOutputPosition] = b; currentOutputPosition++; } } diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java index a04bbe7ec..b79c5cb00 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC2965PortAttributeHandler.java @@ -92,8 +92,8 @@ public class RFC2965PortAttributeHandler implements CookieAttributeHandler { */ private static boolean portMatch(int port, int[] ports) { boolean portInList = false; - for (int i = 0, len = ports.length; i < len; i++) { - if (port == ports[i]) { + for (int port2 : ports) { + if (port == port2) { portInList = true; break; } diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java index 2934b5d63..7f4d07f42 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java @@ -194,8 +194,8 @@ public class TestURLEncodedUtils { private static String constructString(int [] unicodeChars) { StringBuffer buffer = new StringBuffer(); if (unicodeChars != null) { - for (int i = 0; i < unicodeChars.length; i++) { - buffer.append((char)unicodeChars[i]); + for (int unicodeChar : unicodeChars) { + buffer.append((char)unicodeChar); } } return buffer.toString(); diff --git a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java index 96f1029f3..3aa56431b 100644 --- a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java +++ b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java @@ -58,8 +58,8 @@ public class TestBasicScheme { public void testBasicAuthenticationWith88591Chars() throws Exception { int[] germanChars = { 0xE4, 0x2D, 0xF6, 0x2D, 0xFc }; StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < germanChars.length; i++) { - buffer.append((char)germanChars[i]); + for (int germanChar : germanChars) { + buffer.append((char)germanChar); } UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("dh", buffer.toString()); diff --git a/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java b/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java index d1f581ff8..34874c94f 100644 --- a/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java +++ b/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java @@ -421,8 +421,7 @@ public class TestDigestScheme { } HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null); Map map = new HashMap(elements.length); - for (int i = 0; i < elements.length; i++) { - HeaderElement element = elements[i]; + for (HeaderElement element : elements) { map.put(element.getName(), element.getValue()); } return map; diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java index 2bc2b46de..011d54e59 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java @@ -95,13 +95,11 @@ public class TestConnectionReuse { 10, false); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; + for (WorkerThread worker : workers) { worker.start(); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; - workers[i].join(10000); + for (WorkerThread worker : workers) { + worker.join(10000); Exception ex = worker.getException(); if (ex != null) { throw ex; @@ -155,13 +153,11 @@ public class TestConnectionReuse { 10, false); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; + for (WorkerThread worker : workers) { worker.start(); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; - workers[i].join(10000); + for (WorkerThread worker : workers) { + worker.join(10000); Exception ex = worker.getException(); if (ex != null) { throw ex; @@ -205,13 +201,11 @@ public class TestConnectionReuse { 10, true); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; + for (WorkerThread worker : workers) { worker.start(); } - for (int i = 0; i < workers.length; i++) { - WorkerThread worker = workers[i]; - workers[i].join(10000); + for (WorkerThread worker : workers) { + worker.join(10000); Exception ex = worker.getException(); if (ex != null) { throw ex; diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java index 18b36f645..737b9e37a 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java @@ -72,12 +72,12 @@ public class TestIdleConnectionEviction extends LocalServerTestBase { for (int i = 0; i < workers.length; i++) { workers[i] = new WorkerThread(httpclient, target, httpget, 200); } - for (int i = 0; i < workers.length; i++) { - workers[i].start(); + for (WorkerThread worker : workers) { + worker.start(); } - for (int i = 0; i < workers.length; i++) { - workers[i].join(); - Exception ex = workers[i].getException(); + for (WorkerThread worker : workers) { + worker.join(); + Exception ex = worker.getException(); if (ex != null) { throw ex; } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java index 304af3fbd..53a4f44a9 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java @@ -119,22 +119,21 @@ public class TestStatefulConnManagement extends IntegrationTestBase { context, requestCount, target, this.httpclient); } - for (int i = 0; i < workers.length; i++) { - workers[i].start(); + for (HttpWorker worker : workers) { + worker.start(); } - for (int i = 0; i < workers.length; i++) { - workers[i].join(10000); + for (HttpWorker worker : workers) { + worker.join(10000); } - for (int i = 0; i < workers.length; i++) { - Exception ex = workers[i].getException(); + for (HttpWorker worker : workers) { + Exception ex = worker.getException(); if (ex != null) { throw ex; } - Assert.assertEquals(requestCount, workers[i].getCount()); + Assert.assertEquals(requestCount, worker.getCount()); } - for (int i = 0; i < contexts.length; i++) { - HttpContext context = contexts[i]; + for (HttpContext context : contexts) { String uid = (String) context.getAttribute("user"); for (int r = 0; r < requestCount; r++) { diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/ConnPoolBench.java b/httpclient/src/test/java/org/apache/http/impl/conn/ConnPoolBench.java index 60a1a4621..2ebb573c0 100644 --- a/httpclient/src/test/java/org/apache/http/impl/conn/ConnPoolBench.java +++ b/httpclient/src/test/java/org/apache/http/impl/conn/ConnPoolBench.java @@ -65,11 +65,11 @@ public class ConnPoolBench { workers[i] = new WorkerThread1(pool, reps); } long start = System.currentTimeMillis(); - for (int i = 0; i < workers.length; i++) { - workers[i].start(); + for (WorkerThread1 worker : workers) { + worker.start(); } - for (int i = 0; i < workers.length; i++) { - workers[i].join(); + for (WorkerThread1 worker : workers) { + worker.join(); } long finish = System.currentTimeMillis(); float totalTimeSec = (float) (finish - start) / 1000; @@ -93,11 +93,11 @@ public class ConnPoolBench { workers[i] = new WorkerThread2(pool, reps); } long start = System.currentTimeMillis(); - for (int i = 0; i < workers.length; i++) { - workers[i].start(); + for (WorkerThread2 worker : workers) { + worker.start(); } - for (int i = 0; i < workers.length; i++) { - workers[i].join(); + for (WorkerThread2 worker : workers) { + worker.join(); } long finish = System.currentTimeMillis(); float totalTimeSec = (float) (finish - start) / 1000; diff --git a/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java b/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java index 8e12bd427..39e81c4eb 100644 --- a/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java +++ b/httpclient/src/test/java/org/apache/http/localserver/LocalTestServer.java @@ -33,7 +33,6 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; @@ -281,8 +280,7 @@ public class LocalTestServer { t.shutdown(); } synchronized (workers) { - for (Iterator it = workers.iterator(); it.hasNext(); ) { - Worker worker = it.next(); + for (Worker worker : workers) { worker.shutdown(); } } diff --git a/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java b/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java index f1c220204..87c494926 100644 --- a/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java +++ b/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java @@ -215,8 +215,8 @@ public class TestMultipartForm { private static String constructString(int [] unicodeChars) { StringBuilder buffer = new StringBuilder(); if (unicodeChars != null) { - for (int i = 0; i < unicodeChars.length; i++) { - buffer.append((char)unicodeChars[i]); + for (int unicodeChar : unicodeChars) { + buffer.append((char)unicodeChar); } } return buffer.toString();