Examples of HproseWriter


Examples of hprose.io.HproseWriter

        return result;
    }

    private void doOutput(String functionName, Object[] arguments, boolean byRef, OutputStream ostream) throws IOException {
        if (filter != null) ostream = filter.outputFilter(ostream);
        HproseWriter hproseWriter = new HproseWriter(ostream);
        ostream.write(HproseTags.TagCall);
        hproseWriter.writeString(functionName, false);
        if ((arguments != null) && (arguments.length > 0 || byRef)) {
            hproseWriter.reset();
            hproseWriter.writeArray(arguments, false);
            if (byRef) {
                hproseWriter.writeBoolean(true);
            }
        }
        ostream.write(HproseTags.TagEnd);
    }
View Full Code Here

Examples of hprose.io.HproseWriter

        return result;
    }

    private void doOutput(String functionName, Object[] arguments, boolean byRef, OutputStream ostream) throws IOException {
        if (filter != null) ostream = filter.outputFilter(ostream);
        HproseWriter hproseWriter = new HproseWriter(ostream, mode);
        ostream.write(HproseTags.TagCall);
        hproseWriter.writeString(functionName, false);
        if ((arguments != null) && (arguments.length > 0 || byRef)) {
            hproseWriter.reset();
            hproseWriter.writeArray(arguments, false);
            if (byRef) {
                hproseWriter.writeBoolean(true);
            }
        }
        ostream.write(HproseTags.TagEnd);
    }
View Full Code Here

Examples of hprose.io.HproseWriter

        return result;
    }

    private void doOutput(String functionName, Object[] arguments, boolean byRef, OutputStream ostream) throws IOException {
        if (filter != null) ostream = filter.outputFilter(ostream);
        HproseWriter hproseWriter = new HproseWriter(ostream);
        ostream.write(HproseTags.TagCall);
        hproseWriter.writeString(functionName, false);
        if ((arguments != null) && (arguments.length > 0 || byRef)) {
            hproseWriter.reset();
            hproseWriter.writeArray(arguments, false);
            if (byRef) {
                hproseWriter.writeBoolean(true);
            }
        }
        ostream.write(HproseTags.TagEnd);
    }
View Full Code Here

Examples of hprose.io.HproseWriter

        return arguments;
    }

    protected void sendError(OutputStream ostream, String error) throws IOException {
        ByteArrayOutputStream data = new ByteArrayOutputStream();
        HproseWriter writer = new HproseWriter(data, mode);
        data.write(HproseTags.TagError);
        writer.writeString(error);
        data.write(HproseTags.TagEnd);
        responseEnd(ostream, data, error);
    }
View Full Code Here

Examples of hprose.io.HproseWriter

    }

    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);
View Full Code Here

Examples of hprose.io.HproseWriter

        names.addAll(getGlobalMethods().getAllNames());
        if (methods != null) {
            names.addAll(methods.getAllNames());
        }
        ByteArrayOutputStream data = new ByteArrayOutputStream();
        HproseWriter writer = new HproseWriter(data, mode);
        data.write(HproseTags.TagFunctions);
        writer.writeList(names);
        data.write(HproseTags.TagEnd);
        responseEnd(ostream, data, null);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.