diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2012-03-21 19:08:47 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2012-03-21 19:08:47 +0000 |
commit | bbf66bc5239e55a0edc5239c43be70a1fb8032ed (patch) | |
tree | 1b0735712098b5b0e9b25c8f50617472810b1db6 | |
parent | bc8a9da92105e3d0b043f81927b78a7eb0c4c28e (diff) |
Handle inputstream to outputstream copy
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1303509 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java index cb76f74baa..1151d59570 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java +++ b/sca-java-2.x/trunk/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/jackson/JSON2OutputStream.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.databinding.json.jackson; +import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import org.apache.tuscany.sca.databinding.PushTransformer; @@ -48,7 +50,19 @@ public class JSON2OutputStream implements PushTransformer<Object, OutputStream> if (source == null) { return; } - if (source instanceof JsonNode) { + if (source instanceof InputStream) { + try { + InputStream input = (InputStream) source; + byte[] buffer = new byte[4096]; + int n = 0; + while (-1 != (n = input.read(buffer))) { + sink.write(buffer, 0, n); + } + input.close(); + } catch(IOException e) { + throw new TransformationException(e); + } + } else if (source instanceof JsonNode) { JacksonHelper.write((JsonNode)source, sink); } else if (source instanceof JsonParser) { JacksonHelper.write((JsonParser)source, sink); |