cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r785281 - /cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
Date Tue, 16 Jun 2009 16:21:35 GMT
Author: dkulp
Date: Tue Jun 16 16:21:35 2009
New Revision: 785281

URL: http://svn.apache.org/viewvc?rev=785281&view=rev
Log:
[CXF-2289] If CachedOutputStream cannot create the file, continue with it in memory.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=785281&r1=785280&r2=785281&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Tue Jun 16 16:21:35
2009
@@ -73,8 +73,8 @@
 
     private boolean inmem;
 
+    private boolean tempFileFailed;
     private File tempFile;
-
     private File outputDir = DEFAULT_TEMP_DIR;
 
     private List<CachedOutputStreamCallback> callbacks;
@@ -241,7 +241,7 @@
     public int size() {
         return totalLength;
     }
-    
+
     public byte[] getBytes() throws IOException {
         flush();
         if (inmem) {
@@ -256,7 +256,7 @@
             return IOUtils.readBytesFromStream(fin);
         }
     }
-    
+
     public void writeCacheTo(OutputStream out) throws IOException {
         flush();
         if (inmem) {
@@ -278,7 +278,7 @@
             writeCacheTo(out);
             return;
         }
-        
+
         int count = 0;
         if (inmem) {
             if (currentStream instanceof ByteArrayOutputStream) {
@@ -298,7 +298,7 @@
                 }
                 out.append(IOUtils.newStringFromBytes(bytes, 0, x));
                 count += x;
-                
+
                 if (count >= limit) {
                     x = -1;
                 } else {
@@ -328,8 +328,8 @@
             }
             fin.close();
         }
-    }    
-    
+    }
+
 
     /**
      * @return the underlying output stream
@@ -355,7 +355,7 @@
     }
 
     protected void onWrite() throws IOException {
-        
+
     }
 
     public void write(byte[] b, int off, int len) throws IOException {
@@ -392,17 +392,29 @@
     }
 
     private void createFileOutputStream() throws IOException {
+        if (tempFileFailed) {
+            return;
+        }
         ByteArrayOutputStream bout = (ByteArrayOutputStream)currentStream;
-        if (outputDir == null) {
-            tempFile = FileUtils.createTempFile("cos", "tmp");
-        } else {
-            tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
+        try {
+            if (outputDir == null) {
+                tempFile = FileUtils.createTempFile("cos", "tmp");
+            } else {
+                tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
+            }
+            
+            currentStream = new BufferedOutputStream(new FileOutputStream(tempFile));
+            bout.writeTo(currentStream);
+            inmem = false;
+            streamList.add(currentStream);
+        } catch (Exception ex) {
+            //Could be IOException or SecurityException or other issues.
+            //Don't care what, just keep it in memory.
+            tempFileFailed = true;
+            tempFile = null;
+            inmem = true;
+            currentStream = bout;
         }
-        
-        currentStream = new BufferedOutputStream(new FileOutputStream(tempFile));
-        bout.writeTo(currentStream);
-        inmem = false;
-        streamList.add(currentStream);
     }
 
     public File getTempFile() {



Mime
View raw message