cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/2] cxf git commit: Support streaming out of Images for SwA
Date Thu, 17 Aug 2017 14:27:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 740c94918 -> c4e4b45dc


Support streaming out of Images for SwA


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0286b033
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0286b033
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0286b033

Branch: refs/heads/master
Commit: 0286b033005dd68891f975e41359171c3d41efa8
Parents: 740c949
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Aug 17 10:25:21 2017 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu Aug 17 10:25:21 2017 -0400

----------------------------------------------------------------------
 .../jaxws/interceptors/SwAOutInterceptor.java   | 51 ++++++++++++--------
 1 file changed, 30 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0286b033/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
index 97804a5..cb22201 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
@@ -24,6 +24,8 @@ import java.awt.MediaTracker;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.reflect.Method;
 import java.nio.charset.StandardCharsets;
 import java.security.AccessController;
@@ -59,6 +61,7 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBinding;
@@ -180,29 +183,35 @@ public class SwAOutInterceptor extends AbstractSoapInterceptor {
             if (o instanceof Source) {
                 dh = new DataHandler(createDataSource((Source)o, ct));
             } else if (o instanceof Image) {
-                // TODO: make this streamable. This is one of my pet
-                // peeves in JAXB RI as well, so if you fix this, submit the
-                // code to the JAXB RI as well (see RuntimeBuiltinLeafInfoImpl)! - DD
-                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(ct);
-                if (writers.hasNext()) {
-                    ImageWriter writer = writers.next();
+                final Image img = (Image)o;
+                final String contentType = ct;
+                dh = new DataHandler(o, ct) {
+                    @Override
+                    public InputStream getInputStream() throws IOException {
+                        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
+                        writeTo(bout);
+                        return bout.createInputStream();
+                    }
 
-                    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) {
-                        BufferedImage bimg = convertToBufferedImage((Image) o);
-                        ImageOutputStream out = ImageIO.createImageOutputStream(bos);
-                        writer.setOutput(out);
-                        writer.write(bimg);
-                        writer.dispose();
-                        out.flush();
-                        out.close();
-                        dh = new DataHandler(new ByteDataSource(bos.toByteArray(), ct));
-                    } catch (IOException e) {
-                        throw new Fault(e);
+                    @Override
+                    public void writeTo(OutputStream out) throws IOException {
+                        ImageWriter writer = null;
+                        Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(contentType);
+                        if (writers.hasNext()) {
+                            writer = writers.next();
+                        }
+                        if (writer != null) {
+                            BufferedImage bimg = convertToBufferedImage(img);
+                            ImageOutputStream iout = ImageIO.createImageOutputStream(out);
+                            writer.setOutput(iout);
+                            writer.write(bimg);
+                            writer.dispose();
+                            out.flush();
+                        }
                     }
-                } else {
-                    throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED",
-                                     LOG, ct));
-                }
+                    
+                };
+                
             } else if (o instanceof DataHandler) {
                 dh = (DataHandler) o;
                 ct = dh.getContentType();


Mime
View raw message