2002/05/28 18:30:30
[org.ibex.core.git] / src / org / xwt / XMLRPC.java
index 8aa3321..efe4959 100644 (file)
@@ -95,7 +95,7 @@ class XMLRPC extends XML implements Function {
             objects.setElementAt(new Double(new String(content.getBuf(), 0, content.size())), objects.size() - 1);
 
         else if (name.equals("base64"))
-            objects.setElementAt(new String(Base64.decode(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
+            objects.setElementAt(new ByteStream(Base64.decode(new String(content.getBuf(), 0, content.size()))), objects.size() - 1);
 
         else if (name.equals("name"))
             objects.addElement(new String(content.getBuf(), 0, content.size()));
@@ -182,6 +182,31 @@ class XMLRPC extends XML implements Function {
             sb.append(((Boolean)o).booleanValue() ? "1" : "0");
             sb.append("</boolean></value>\n");
 
+        } else if (o instanceof ByteStream) {
+            try {
+                sb.append("                <value><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("\n              </base64></value>\n");
+            } catch (IOException e) {
+                if (Log.on) Log.log(this, "caught IOException while attempting to send a ByteStream via XML-RPC");
+                if (Log.on) Log.log(this, e);
+                throw new JavaScriptException("caught IOException while attempting to send a ByteStream via XML-RPC");
+            }
+
         } else if (o instanceof String) {
             sb.append("                <value><string>");
             String s = (String)o;