manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1408433 - /manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java
Date Mon, 12 Nov 2012 20:02:45 GMT
Author: kwright
Date: Mon Nov 12 20:02:45 2012
New Revision: 1408433

URL: http://svn.apache.org/viewvc?rev=1408433&view=rev
Log:
Throw an InterruptedIOException if the thread is interrupted.

Modified:
    manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java

Modified: manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java?rev=1408433&r1=1408432&r2=1408433&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java
(original)
+++ manifoldcf/branches/CONNECTORS-120/framework/core/src/main/java/org/apache/manifoldcf/core/common/XThreadInputStream.java
Mon Nov 12 20:02:45 2012
@@ -105,37 +105,50 @@ public class XThreadInputStream extends 
   public int read(byte[] b, int off, int len)
     throws IOException
   {
-    int totalAmt = 0;
-    while (true)
+    try
     {
-      if (len == 0)
-        return 0;
-      int copyLen;
-      synchronized (this)
+      int totalAmt = 0;
+      while (true)
       {
-        if (streamEnd)
+        if (len == 0)
+          return 0;
+        int copyLen;
+        synchronized (this)
         {
-          if (totalAmt != 0)
-            return totalAmt;
-          return -1;
+          copyLen = byteCount;
+          if (copyLen > len)
+            copyLen = len;
+          int remLen = buffer.length - startPoint;
+          if (copyLen > remLen)
+            copyLen = remLen;
+          if (copyLen == 0)
+          {
+            if (streamEnd)
+            {
+              if (totalAmt != 0)
+                return totalAmt;
+              return -1;
+            }
+            wait();
+            continue;
+          }
+        }
+        System.arraycopy(buffer, startPoint, b, off, copyLen);
+        totalAmt += copyLen;
+        len -= copyLen;
+        synchronized (this)
+        {
+          startPoint += copyLen;
+          startPoint &= (buffer.length - 1);
+          byteCount -= copyLen;
+          notifyAll();
         }
-        copyLen = byteCount;
-        if (copyLen > len)
-          copyLen = len;
-        int remLen = buffer.length - startPoint;
-        if (copyLen > remLen)
-          copyLen = remLen;
-      }
-      System.arraycopy(buffer, startPoint, b, off, copyLen);
-      totalAmt += copyLen;
-      len -= copyLen;
-      synchronized (this)
-      {
-        startPoint += copyLen;
-        startPoint &= (buffer.length - 1);
-        byteCount -= copyLen;
       }
     }
+    catch (InterruptedException e)
+    {
+      throw new InterruptedIOException(e.getMessage());
+    }
   }
   
   /** Skip



Mime
View raw message