Author: kwright
Date: Tue Jul  1 08:51:29 2014
New Revision: 1607023

URL: http://svn.apache.org/r1607023
Log:
Regularize error handling

Modified:
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/BinaryInput.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/CharacterInput.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileCharacterInput.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileInput.java

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/BinaryInput.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/BinaryInput.java?rev=1607023&r1=1607022&r2=1607023&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/BinaryInput.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/BinaryInput.java
 Tue Jul  1 08:51:29 2014
@@ -95,14 +95,18 @@ public abstract class BinaryInput extend
       stream.close();
       stream = null;
     }
-    catch (InterruptedIOException e)
-    {
-      throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
     catch (IOException e)
     {
-      throw new ManifoldCFException("IO exception closing stream: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+      handleIOException(e,"closing stream");
     }
   }
 
+  protected static void handleIOException(IOException e, String context)
+    throws ManifoldCFException
+  {
+    if (e instanceof InterruptedIOException)
+      throw new 
ManifoldCFException(e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+    throw new ManifoldCFException("IO exception while "+context+": 
"+e.getMessage(),e);
+  }
+
 }

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/CharacterInput.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/CharacterInput.java?rev=1607023&r1=1607022&r2=1607023&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/CharacterInput.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/CharacterInput.java
 Tue Jul  1 08:51:29 2014
@@ -107,13 +107,9 @@ public abstract class CharacterInput ext
       stream.close();
       stream = null;
     }
-    catch (InterruptedIOException e)
-    {
-      throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
     catch (IOException e)
     {
-      throw new ManifoldCFException("Error closing stream: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+      handleIOException(e, "closing stream");
     }
   }
 
@@ -125,4 +121,12 @@ public abstract class CharacterInput ext
   protected abstract void calculateHashValue()
     throws ManifoldCFException;
 
+  protected static void handleIOException(IOException e, String context)
+    throws ManifoldCFException
+  {
+    if (e instanceof InterruptedIOException)
+      throw new 
ManifoldCFException(e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+    throw new ManifoldCFException("IO exception while "+context+": 
"+e.getMessage(),e);
+  }
+
 }

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileCharacterInput.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileCharacterInput.java?rev=1607023&r1=1607022&r2=1607023&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileCharacterInput.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileCharacterInput.java
 Tue Jul  1 08:51:29 2014
@@ -109,13 +109,9 @@ public class TempFileCharacterInput exte
         chunkTotal += readsize;
       }
     }
-    catch (InterruptedIOException e)
-    {
-      throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
     catch (IOException e)
     {
-      throw new ManifoldCFException("Cannot read character stream: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+      handleIOException(e,"reading character stream");
     }
     
     // Set up hash digest, and calculate the initial hash.
@@ -205,18 +201,16 @@ public class TempFileCharacterInput exte
             throw (Error)e;
           if (e instanceof RuntimeException)
             throw (RuntimeException)e;
-          if (e instanceof Exception)
-            throw (Exception)e;
-          throw new Exception("Unexpected throwable: "+e.getMessage(),e);
+          if (e instanceof ManifoldCFException)
+            throw (ManifoldCFException)e;
+          if (e instanceof IOException)
+            throw (IOException)e;
+          throw new RuntimeException("Unexpected throwable of type 
"+e.getClass().getName()+": "+e.getMessage(),e);
         }
       }
-      catch (InterruptedIOException e)
-      {
-        throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (Exception e)
+      catch (IOException e)
       {
-        throw new ManifoldCFException("Cannot write temporary file: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+        handleIOException(e,"writing temporary file");
       }
     }
     
@@ -387,13 +381,9 @@ public class TempFileCharacterInput exte
         reader.close();
       }
     }
-    catch (InterruptedIOException e)
-    {
-      throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
     catch (IOException e)
     {
-      throw new ManifoldCFException("Can't scan file: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+      handleIOException(e,"scanning file");
     }
   }
 

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileInput.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileInput.java?rev=1607023&r1=1607022&r2=1607023&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileInput.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/TempFileInput.java
 Tue Jul  1 08:51:29 2014
@@ -101,13 +101,9 @@ public class TempFileInput extends Binar
         chunkTotal += readsize;
       }
     }
-    catch (InterruptedIOException e)
-    {
-      throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-    }
     catch (IOException e)
     {
-      throw new ManifoldCFException("Cannot read byte stream: 
"+e.getMessage(),e,ManifoldCFException.GENERAL_ERROR);
+      handleIOException(e,"reading byte stream");
     }
 
     if (eofSeen && chunkTotal < maxMemSize)
@@ -181,18 +177,16 @@ public class TempFileInput extends Binar
             throw (Error)e;
           if (e instanceof RuntimeException)
             throw (RuntimeException)e;
-          if (e instanceof Exception)
-            throw (Exception)e;
-          throw new Exception("Unexpected throwable: "+e.getMessage(),e);
+          if (e instanceof ManifoldCFException)
+            throw (ManifoldCFException)e;
+          if (e instanceof IOException)
+            throw (IOException)e;
+          throw new RuntimeException("Unexpected throwable of type 
"+e.getClass().getName()+": "+e.getMessage(),e);
         }
       }
-      catch (InterruptedIOException e)
-      {
-        throw new ManifoldCFException("Interrupted: 
"+e.getMessage(),e,ManifoldCFException.INTERRUPTED);
-      }
-      catch (Exception e)
+      catch (IOException e)
       {
-        throw new ManifoldCFException("Cannot write temporary 
file",e,ManifoldCFException.GENERAL_ERROR);
+        handleIOException(e,"writing temporary file");
       }
     }
   }


Reply via email to