You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/06/16 19:08:03 UTC

svn commit: r785299 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Author: dkulp
Date: Tue Jun 16 17:08:03 2009
New Revision: 785299

URL: http://svn.apache.org/viewvc?rev=785299&view=rev
Log:
Merged revisions 785281 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r785281 | dkulp | 2009-06-16 12:21:35 -0400 (Tue, 16 Jun 2009) | 1 line
  
  [CXF-2289] If CachedOutputStream cannot create the file, continue with it in memory.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 16 17:08:03 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784183,784895,785279-785280
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784183,784895,785279-785281

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jun 16 17:08:03 2009
@@ -1 +1 @@
-/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784183,784895,785279-785280
+/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784183,784895,785279-785281

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=785299&r1=785298&r2=785299&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java (original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Tue Jun 16 17:08:03 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() {