harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r937991 - in /harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal: FileChannelImpl.java SocketChannelImpl.java
Date Mon, 26 Apr 2010 10:14:17 GMT
Author: hindessm
Date: Mon Apr 26 10:14:16 2010
New Revision: 937991

URL: http://svn.apache.org/viewvc?rev=937991&view=rev
Log:
Refactor some common code to methed.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java?rev=937991&r1=937990&r2=937991&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
Mon Apr 26 10:14:16 2010
@@ -298,10 +298,7 @@ public abstract class FileChannelImpl ex
             throw new IndexOutOfBoundsException();
         }
         openCheck();
-        for (int i = offset; i < offset + length; i++) {
-            count += buffers[i].remaining();
-        }
-        if (0 == count) {
+        if (calculateTotalRemaining(buffers, offset, length) == 0) {
             return 0;
         }
         if (size() == 0) {
@@ -570,11 +567,7 @@ public abstract class FileChannelImpl ex
             throw new IndexOutOfBoundsException();
         }
         openCheck();
-        long count = 0;
-        for (int i = offset; i < offset + length; i++) {
-            count += sources[i].remaining();
-        }
-        if (0 == count) {
+        if (calculateTotalRemaining(sources, offset, length) == 0) {
             return 0;
         }
         Object[] src = new Object[length];
@@ -634,4 +627,13 @@ public abstract class FileChannelImpl ex
     public long getHandle() {
         return handle;
     }
+
+    private int calculateTotalRemaining(ByteBuffer[] buffers, int offset,
+            int length) {
+        int count = 0;
+        for (int i = offset; i < offset + length; i++) {
+            count += buffers[i].remaining();
+        }
+        return count;
+    }
 }

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=937991&r1=937990&r2=937991&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
Mon Apr 26 10:14:16 2010
@@ -399,7 +399,7 @@ class SocketChannelImpl extends SocketCh
         }
 
         checkOpenConnected();
-        int totalCount = calculateByteBufferArray(targets, offset, length);
+        int totalCount = calculateTotalRemaining(targets, offset, length);
         if (0 == totalCount) {
             return 0;
         }
@@ -491,11 +491,7 @@ class SocketChannelImpl extends SocketCh
         }
 
         checkOpenConnected();
-        long count = 0;
-        for (int i = offset; i < offset + length; i++) {
-            count += sources[i].remaining();
-        }
-        if (0 == count) {
+        if (calculateTotalRemaining(sources, offset, length) == 0) {
             return 0;
         }
 
@@ -569,13 +565,13 @@ class SocketChannelImpl extends SocketCh
         return writeCount;
     }
 
-    private int calculateByteBufferArray(ByteBuffer[] sources, int offset,
+    private int calculateTotalRemaining(ByteBuffer[] buffers, int offset,
             int length) {
-        int sum = 0;
-        for (int val = offset; val < offset + length; val++) {
-            sum = sum + sources[val].remaining();
+        int count = 0;
+        for (int i = offset; i < offset + length; i++) {
+            count += buffers[i].remaining();
         }
-        return sum;
+        return count;
     }
 
     /*



Mime
View raw message