cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-6006] Support for StreamingOutput on the read side; patch from Gerald Quintana applied This closes #23
Date Wed, 17 Sep 2014 09:24:43 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 8bc72ec08 -> 30529297e


[CXF-6006] Support for StreamingOutput on the read side; patch from Gerald Quintana applied
This closes #23


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

Branch: refs/heads/master
Commit: 30529297e058283728aabf4899606a0847326c54
Parents: 8bc72ec
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Sep 17 10:24:24 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Sep 17 10:24:24 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/BinaryDataProvider.java      | 16 +++++++++++++++-
 .../cxf/jaxrs/provider/BinaryDataProviderTest.java  | 11 +++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/30529297/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
index 431f6fe..d430a68 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
@@ -65,7 +65,18 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
         return byte[].class.isAssignableFrom(type)
                || InputStream.class.isAssignableFrom(type)
                || Reader.class.isAssignableFrom(type)
-               || File.class.isAssignableFrom(type);
+               || File.class.isAssignableFrom(type)
+               || StreamingOutput.class.isAssignableFrom(type);
+    }
+
+    private static final class ReadingStreamingOutput implements StreamingOutput {
+        private final InputStream inputStream;
+        private ReadingStreamingOutput(InputStream inputStream) {
+            this.inputStream = inputStream;
+        }
+        public void write(OutputStream outputStream) throws IOException {
+            IOUtils.copy(inputStream, outputStream);
+        }        
     }
 
     public T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, MediaType
type, 
@@ -99,6 +110,9 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
                 fos.close();
                 return clazz.cast(f);
             }
+            if (StreamingOutput.class.isAssignableFrom(clazz)) {
+                return clazz.cast(new ReadingStreamingOutput(is));
+            }
         } catch (ClassCastException e) {
             String msg = "Unsupported class: " + clazz.getName();
             LOG.warning(msg);

http://git-wip-us.apache.org/repos/asf/cxf/blob/30529297/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
index ffb6fc4..0a9ff02 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
@@ -58,6 +58,7 @@ public class BinaryDataProviderTest extends Assert {
         assertTrue(p.isReadable(byte[].class, null, null, null)
                    && p.isReadable(InputStream.class, null, null, null)
                    && p.isReadable(File.class, null, null, null)
+                   && p.isReadable(StreamingOutput.class, null, null, null)
                    && !p.isReadable(int[].class, null, null, null));
     }
     
@@ -83,6 +84,16 @@ public class BinaryDataProviderTest extends Assert {
                                       new MetadataMap<String, Object>(),
                                       new ByteArrayInputStream("hi".getBytes()));
         assertEquals(IOUtils.toString(r), "hi");
+
+        StreamingOutput so = (StreamingOutput)p.readFrom(StreamingOutput.class, StreamingOutput.class,

+                                      new Annotation[]{}, 
+                                      MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                                      new MetadataMap<String, Object>(),
+                                      new ByteArrayInputStream("hi".getBytes()));
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        so.write(baos);
+        bytes = baos.toByteArray();
+        assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
     }
     
     @SuppressWarnings({ "unchecked", "rawtypes" })


Mime
View raw message