private Object doInput(Object[] arguments, Class returnType, HproseResultMode resultMode, InputStream istream) throws IOException {
int tag;
if (filter != null) istream = filter.inputFilter(istream);
Object result = null;
HproseReader hproseReader = new HproseReader(istream, mode);
ByteArrayOutputStream bytestream = null;
if (resultMode == HproseResultMode.RawWithEndTag || resultMode == HproseResultMode.Raw) {
bytestream = new ByteArrayOutputStream();
}
while ((tag = hproseReader.checkTags(
(char) HproseTags.TagResult + "" +
(char) HproseTags.TagArgument + "" +
(char) HproseTags.TagError + "" +
(char) HproseTags.TagEnd)) != HproseTags.TagEnd) {
switch (tag) {
case HproseTags.TagResult:
if (resultMode == HproseResultMode.Normal) {
hproseReader.reset();
result = hproseReader.unserialize(returnType);
}
else if (resultMode == HproseResultMode.Serialized) {
result = hproseReader.readRaw();
}
else {
bytestream.write(HproseTags.TagResult);
hproseReader.readRaw(bytestream);
}
break;
case HproseTags.TagArgument:
if (resultMode == HproseResultMode.RawWithEndTag || resultMode == HproseResultMode.Raw) {
bytestream.write(HproseTags.TagArgument);
hproseReader.readRaw(bytestream);
}
else {
hproseReader.reset();
Object[] args = (Object[]) hproseReader.readList(Object[].class);
System.arraycopy(args, 0, arguments, 0, arguments.length);
}
break;
case HproseTags.TagError:
if (resultMode == HproseResultMode.RawWithEndTag || resultMode == HproseResultMode.Raw) {
bytestream.write(HproseTags.TagError);
hproseReader.readRaw(bytestream);
}
else {
hproseReader.reset();
result = new HproseException((String) hproseReader.readString());
}
break;
}
}
if (resultMode == HproseResultMode.RawWithEndTag || resultMode == HproseResultMode.Raw) {