http-client-branch: review comment - minor cleanups in SocketTube http-client-branch
authorchegar
Thu, 29 Mar 2018 20:49:13 +0100
branchhttp-client-branch
changeset 56372 98075dcd4ffc
parent 56371 5497ce426276
child 56374 e453d21310bd
http-client-branch: review comment - minor cleanups in SocketTube
src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java	Thu Mar 29 20:22:55 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java	Thu Mar 29 20:49:13 2018 +0100
@@ -914,33 +914,32 @@
         ByteBuffer buf = buffersSource.get();
         assert buf.hasRemaining();
 
-        int read = -1;
+        int read;
         int pos = buf.position();
         List<ByteBuffer> list = null;
         while (buf.hasRemaining()) {
             try {
                 while ((read = channel.read(buf)) > 0) {
-                    if (!buf.hasRemaining()) break;
+                    if (!buf.hasRemaining())
+                        break;
                 }
             } catch (IOException x) {
                 if (buf.position() == pos && (list == null || list.isEmpty())) {
-                    // if we have read no bytes, just throw...
+                    // no bytes have been read, just throw...
                     throw x;
                 } else {
-                    // we have some bytes. return them and fail
-                    // next time.
+                    // some bytes have been read, return them and fail next time
                     errorRef.compareAndSet(null, x);
-                    read = 0; // make sure we will exit the outer loop
+                    read = 0; // ensures outer loop will exit
                 }
             }
 
             // nothing read;
             if (buf.position() == pos) {
-                // An empty list signal the end of data, and should only be
-                // returned if read == -1.
-                // If we already read some data, then we must return what we have
-                // read, and -1 will be returned next time the caller attempts to
-                // read something.
+                // An empty list signals the end of data, and should only be
+                // returned if read == -1. If some data has already been read,
+                // then it must be returned. -1 will be returned next time
+                // the caller attempts to read something.
                 if (list == null && read == -1) {  // eof
                     list = EOF;
                     break;
@@ -956,7 +955,10 @@
                 }
                 list.add(buf);
             }
-            if (read <= 0 || list.size() == MAX_BUFFERS) break;
+            if (read <= 0 || list.size() == MAX_BUFFERS) {
+                break;
+            }
+
             buf = buffersSource.get();
             pos = buf.position();
             assert buf.hasRemaining();