Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 21368DFCF for ; Thu, 9 Aug 2012 15:32:44 +0000 (UTC) Received: (qmail 8916 invoked by uid 500); 9 Aug 2012 15:32:44 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 8873 invoked by uid 500); 9 Aug 2012 15:32:44 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 8866 invoked by uid 99); 9 Aug 2012 15:32:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Aug 2012 15:32:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Aug 2012 15:32:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 765DC23888E3; Thu, 9 Aug 2012 15:31:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1371257 - /cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java Date: Thu, 09 Aug 2012 15:31:59 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120809153159.765DC23888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Thu Aug 9 15:31:59 2012 New Revision: 1371257 URL: http://svn.apache.org/viewvc?rev=1371257&view=rev Log: 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.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java?rev=1371257&r1=1371256&r2=1371257&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java (original) +++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/attachment/ImageDataContentHandler.java Thu Aug 9 15:31:59 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 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 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()); }