}
write('}');
}
public void write(JSONRPCResult result) throws IOException {
JSONObject o = new JSONObject();
if (result.getErrorCode() == JSONRPCResult.CODE_SUCCESS) {
o.put("id", result.getId());
o.put("result", result.getResult());
} else if (result.getErrorCode() == JSONRPCResult.CODE_REMOTE_EXCEPTION) {
Throwable e = (Throwable) result.getResult();
CharArrayWriter caw = new CharArrayWriter();
e.printStackTrace(new PrintWriter(caw));
JSONObject err = new JSONObject();
err.put("code", Integer.valueOf(result.getErrorCode()));
err.put("msg", e.getMessage());
err.put("trace", caw.toString());
o.put("id", result.getId());
o.put("error", err);
} else {
JSONObject err = new JSONObject();
err.put("code", Integer.valueOf(result.getErrorCode()));
err.put("msg", result.getResult());
o.put("id", result.getId());
o.put("error", err);
}
write(o);
}