}
protected void doInvoke(InputStream istream, OutputStream ostream, HproseMethods methods) throws Throwable {
HproseReader reader = new HproseReader(istream, mode);
ByteArrayOutputStream data = new ByteArrayOutputStream();
HproseWriter writer = new HproseWriter(data, mode);
int tag;
do {
reader.reset();
String name = ((String) reader.readString());
String aliasname = name.toLowerCase();
HproseMethod remoteMethod = null;
int count = 0;
Object[] args, arguments;
boolean byRef = false;
tag = reader.checkTags((char) HproseTags.TagList + "" +
(char) HproseTags.TagEnd + "" +
(char) HproseTags.TagCall);
if (tag == HproseTags.TagList) {
reader.reset();
count = reader.readInt(HproseTags.TagOpenbrace);
if (methods != null) {
remoteMethod = methods.get(aliasname, count);
}
if (remoteMethod == null) {
remoteMethod = getGlobalMethods().get(aliasname, count);
}
if (remoteMethod == null) {
arguments = reader.readArray(count);
}
else {
arguments = new Object[count];
reader.readArray(remoteMethod.paramTypes, arguments, count);
}
reader.checkTag(HproseTags.TagClosebrace);
tag = reader.checkTags((char) HproseTags.TagTrue + "" +
(char) HproseTags.TagEnd + "" +
(char) HproseTags.TagCall);
if (tag == HproseTags.TagTrue) {
byRef = true;
tag = reader.checkTags((char) HproseTags.TagEnd + "" +
(char) HproseTags.TagCall);
}
}
else {
if (methods != null) {
remoteMethod = methods.get(aliasname, 0);
}
if (remoteMethod == null) {
remoteMethod = getGlobalMethods().get(aliasname, 0);
}
arguments = new Object[0];
}
if (event != null) {
event.onBeforeInvoke(name, arguments, byRef);
}
if (remoteMethod == null) {
args = arguments;
}
else {
args = fixArguments(remoteMethod.paramTypes, arguments, count);
}
Object result;
try {
if (remoteMethod == null) {
if (methods != null) {
remoteMethod = methods.get("*", 2);
}
if (remoteMethod == null) {
remoteMethod = getGlobalMethods().get("*", 2);
}
if (remoteMethod == null) {
throw new NoSuchMethodError("Can't find this method " + name);
}
result = remoteMethod.method.invoke(remoteMethod.obj, new Object[]{name, args});
}
else {
result = remoteMethod.method.invoke(remoteMethod.obj, args);
}
}
catch (ExceptionInInitializerError ex1) {
Throwable e = ex1.getCause();
if (e != null) {
throw e;
}
throw ex1;
}
catch (InvocationTargetException ex2) {
Throwable e = ex2.getCause();
if (e != null) {
throw e;
}
throw ex2;
}
if (byRef) {
System.arraycopy(args, 0, arguments, 0, count);
}
if (event != null) {
event.onAfterInvoke(name, arguments, byRef, result);
}
if (remoteMethod.mode == HproseResultMode.RawWithEndTag) {
data.write((byte[])result);
responseEnd(ostream, data, null);
return;
}
else if (remoteMethod.mode == HproseResultMode.Raw) {
data.write((byte[])result);
}
else {
data.write(HproseTags.TagResult);
if (remoteMethod.mode == HproseResultMode.Serialized) {
data.write((byte[])result);
}
else {
writer.reset();
writer.serialize(result);
}
if (byRef) {
writer.reset();
data.write(HproseTags.TagArgument);
writer.writeArray(arguments, false);
}
}
} while (tag == HproseTags.TagCall);
data.write(HproseTags.TagEnd);
responseEnd(ostream, data, null);