Author: thorsten
Date: Fri Apr 30 17:01:56 2010
New Revision: 939737

URL: http://svn.apache.org/viewvc?rev=939737&view=rev
Log:
DROIDS-13
Reporter: thorsten
Patch:   Richard Frovarp

Modified:
    
incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java

Modified: 
incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
URL: 
http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java?rev=939737&r1=939736&r2=939737&view=diff
==============================================================================
--- 
incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
 (original)
+++ 
incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
 Fri Apr 30 17:01:56 2010
@@ -56,7 +56,7 @@ public class Save extends WriterHandler 
     }
   }
 
-  private void writeOutput(InputStream stream) throws IOException {
+  private void writeOutput(InputStream stream)  throws IOException {
     if (!uri.getPath().endsWith("/")) {
       byte[] buffer = new byte[bufferSize];
       int length = -1;
@@ -69,13 +69,23 @@ public class Save extends WriterHandler 
       }
       log.info("Trying to save " + uri + " to " + file);
       File cache = new File(file);
-      createFile(cache);
-      OutputStream output = new BufferedOutputStream(new 
FileOutputStream(cache));
-      
-      while ((length = stream.read(buffer)) > -1) {
-        output.write(buffer, 0, length);
+      OutputStream output =null;
+      try {
+        createFile(cache);
+        output = new BufferedOutputStream(new FileOutputStream(cache));
+          
+          while ((length = stream.read(buffer)) > -1) {
+            output.write(buffer, 0, length);
+        }
+          
+    } catch (IOException e) {
+        throw e;
+    } finally{
+        if (null != output) {
+            output.flush();
+            output.close();
+        }
     }
-      output.flush();
     }
   }
 


Reply via email to