cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1371464 - /cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java
Date Thu, 09 Aug 2012 20:35:51 GMT
Author: dkulp
Date: Thu Aug  9 20:35:50 2012
New Revision: 1371464

URL: http://svn.apache.org/viewvc?rev=1371464&view=rev
Log:
Merged revisions 1371435 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

........
  r1371435 | dkulp | 2012-08-09 16:23:41 -0400 (Thu, 09 Aug 2012) | 18 lines

  Merged revisions 1371257 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

  ........
    r1371257 | dkulp | 2012-08-09 11:31:59 -0400 (Thu, 09 Aug 2012) | 10 lines

    Merged revisions 1368661 via  git cherry-pick from
    https://svn.apache.org/repos/asf/cxf/trunk

    ........
      r1368661 | dkulp | 2012-08-02 15:43:29 -0400 (Thu, 02 Aug 2012) | 2 lines

      Add some extra formats for the image handler

    ........

  ........

........

Modified:
    cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java

Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java?rev=1371464&r1=1371463&r2=1371464&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java
Thu Aug  9 20:35:50 2012
@@ -26,7 +26,10 @@ import java.awt.MediaTracker;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.UnsupportedFlavorException;
 import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Iterator;
 
@@ -37,6 +40,8 @@ import javax.imageio.ImageIO;
 import javax.imageio.ImageWriter;
 import javax.imageio.stream.ImageOutputStream;
 
+import org.apache.cxf.helpers.IOUtils;
+
 /**
  * 
  */
@@ -51,6 +56,10 @@ public class ImageDataContentHandler imp
         }
     }
 
+    public ImageDataContentHandler() {
+        
+    }
+    
     public Object getContent(DataSource ds) throws IOException {
         return ImageIO.read(ds.getInputStream());
     }
@@ -70,17 +79,27 @@ public class ImageDataContentHandler imp
     }
 
     public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException
{
-        Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
-        if (writers.hasNext()) {
-            ImageWriter writer = writers.next();
-            
-            BufferedImage bimg = convertToBufferedImage((Image)obj);
-            ImageOutputStream out = ImageIO.createImageOutputStream(os); 
-            writer.setOutput(out);
-            writer.write(bimg);
-            writer.dispose();
-            out.flush();
-            out.close();
+        if (obj instanceof Image) {
+            Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
+            if (writers.hasNext()) {
+                ImageWriter writer = writers.next();
+                
+                BufferedImage bimg = convertToBufferedImage((Image)obj);
+                ImageOutputStream out = ImageIO.createImageOutputStream(os); 
+                writer.setOutput(out);
+                writer.write(bimg);
+                writer.dispose();
+                out.flush();
+                out.close();
+                return;
+            }
+        } else if (obj instanceof byte[]) {
+            os.write((byte[])obj);
+        } else if (obj instanceof InputStream) {
+            IOUtils.copyAndCloseInput((InputStream)obj, os);
+        } else if (obj instanceof File) {
+            FileInputStream file = new FileInputStream((File)obj);
+            IOUtils.copyAndCloseInput(file, os);
         } else {
             throw new IOException("Attachment type not spported " + obj.getClass());    
               
         }



Mime
View raw message