2002/05/28 18:30:30
[org.ibex.core.git] / src / org / xwt / SOAP.java
index ade85e5..02f3583 100644 (file)
@@ -91,7 +91,7 @@ class SOAP extends XMLRPC {
 
             } else if (me instanceof byte[]) {
                 objects.removeElementAt(objects.size() - 1);
-                objects.addElement(new String(Base64.decode(new String(content.getBuf(), 0, content.size()))));
+                objects.addElement(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))));
                 content.reset();                
                 
             } else if (me instanceof Integer) {
@@ -159,7 +159,7 @@ class SOAP extends XMLRPC {
     }
 
     /** Appends the SOAP representation of <code>o</code> to <code>sb</code> */
-    void appendObject(String name, Object o, StringBuffer sb) {
+    void appendObject(String name, Object o, StringBuffer sb) throws JavaScriptException {
         if (o instanceof Number) {
             if ((double)((Number)o).intValue() == ((Number)o).doubleValue()) {
                 sb.append("                <" + name + " xsi:type=\"xsd:int\">");
@@ -176,6 +176,31 @@ class SOAP extends XMLRPC {
             sb.append(((Boolean)o).booleanValue() ? "true" : "false");
             sb.append("</" + name + ">\n");
 
+        } else if (o instanceof ByteStream) {
+            try {
+                sb.append("                <" + name + " xsi:type=\"xsd:base64\">");
+                InputStream is = ((ByteStream)o).getInputStream();
+                byte[] buf = new byte[96];
+                while(true) {
+                    int numread = is.read(buf, 0, 96);
+                    if (numread == -1) break;
+                    byte[] writebuf = buf;
+                    if (numread < buf.length) {
+                        writebuf = new byte[numread];
+                        System.arraycopy(buf, 0, writebuf, 0, numread);
+                    }
+                    sb.append("              ");
+                    sb.append(Base64.encode(writebuf));
+                    sb.append("\n");
+                }
+                sb.append(((Boolean)o).booleanValue() ? "1" : "0");
+                sb.append("</" + name + ">\n");
+            } catch (IOException e) {
+                if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via SOAP");
+                if (Log.on) Log.log(this, e);
+                throw new JavaScriptException("caught IOException while attempting to send a ByteStream via SOAP");
+            }
+
         } else if (o instanceof String) {
             sb.append("                <" + name + " xsi:type=\"xsd:string\">");
             String s = (String)o;