X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FXMLRPC.java;h=22247cd24a88c3b9fa2c78d16079a6496cabeb82;hb=521a58f4805f4423ea44d8e768c8fd3710cf8750;hp=8aa33211c6809a4b8adac46178495705cfb6131b;hpb=15a3e1ac3b709d4c756b078e34e6d67f2efbb317;p=org.ibex.core.git
diff --git a/src/org/xwt/XMLRPC.java b/src/org/xwt/XMLRPC.java
index 8aa3321..22247cd 100644
--- a/src/org/xwt/XMLRPC.java
+++ b/src/org/xwt/XMLRPC.java
@@ -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,30 @@ class XMLRPC extends XML implements Function {
sb.append(((Boolean)o).booleanValue() ? "1" : "0");
sb.append("\n");
+ } else if (o instanceof ByteStream) {
+ try {
+ sb.append(" \n");
+ InputStream is = ((ByteStream)o).getInputStream();
+ byte[] buf = new byte[54];
+ while(true) {
+ int numread = is.read(buf, 0, 54);
+ 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(new String(Base64.encode(writebuf)));
+ sb.append("\n");
+ }
+ sb.append("\n \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(" ");
String s = (String)o;
@@ -268,13 +292,11 @@ class XMLRPC extends XML implements Function {
new BufferedReader(new FilterReader(new InputStreamReader(new Filter(http.getInputStream()))) {
public int read() throws IOException {
int i = super.read();
- System.out.println("X " + i);
if (Log.on) Log.log(this, "recv: " + ((char)i));
return i;
}
public int read(char[] c, int off, int len) throws IOException {
int ret = super.read(c, off, len);
- System.out.println("Y " + ret);
if (ret == -1) return ret;
if (Log.on) Log.log(this, "recv: " + new String(c, off, ret));
return ret;
@@ -319,19 +341,10 @@ class XMLRPC extends XML implements Function {
public final Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args) throws JavaScriptException {
- // put ourselves in the background
- Thread thread = Thread.currentThread();
- if (!(thread instanceof ThreadMessage)) {
- if (Log.on) Log.log(this, "RPC calls may only be made from background threads");
- return null;
- }
- ThreadMessage mythread = (ThreadMessage)thread;
- mythread.setPriority(Thread.MIN_PRIORITY);
- mythread.done.release();
+ if (!ThreadMessage.suspendThread()) return null;
try {
return call(args);
-
} catch (IOException se) {
if (Log.on) Log.log(this, se);
if (Log.on) Log.log(this, " at " + cx.interpreterSourceFile + ":" + cx.interpreterLine);
@@ -344,12 +357,8 @@ class XMLRPC extends XML implements Function {
if (Log.on) Log.log(this, " at " + cx.interpreterSourceFile + ":" + cx.interpreterLine);
}
throw jse;
-
} finally {
- // okay, let ourselves be brought to the foreground
- MessageQueue.add(mythread);
- mythread.setPriority(Thread.NORM_PRIORITY);
- mythread.go.block();
+ ThreadMessage.resumeThread();
}
}