incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r939737 - /incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/handle/Save.java
Date Fri, 30 Apr 2010 17:01:56 GMT
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();
     }
   }
 



Mime
View raw message