burlapoutput.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 965 行 · 第 1/2 页
JAVA
965 行
/* * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved. * * The Apache Software License, Version 1.1 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Caucho Technology (http://www.caucho.com/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "Burlap", "Resin", and "Caucho" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * info@caucho.com. * * 5. Products derived from this software may not be called "Resin" * nor may "Resin" appear in their names without prior written * permission of Caucho Technology. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @author Scott Ferguson */package com.caucho.burlap.io;import com.caucho.hessian.io.Serializer;import com.caucho.hessian.io.SerializerFactory;import java.io.IOException;import java.io.OutputStream;import java.util.Calendar;import java.util.Date;import java.util.IdentityHashMap;import java.util.TimeZone;/** * Output stream for Burlap requests, compatible with microedition * Java. It only uses classes and types available in JDK. * * <p>Since BurlapOutput does not depend on any classes other than * in the JDK, it can be extracted independently into a smaller package. * * <p>BurlapOutput is unbuffered, so any client needs to provide * its own buffering. * * <pre> * OutputStream os = ...; // from http connection * BurlapOutput out = new BurlapOutput(os); * String value; * * out.startCall("hello"); // start hello call * out.writeString("arg1"); // write a string argument * out.completeCall(); // complete the call * </pre> */public class BurlapOutput extends AbstractBurlapOutput { // the output stream protected OutputStream os; // map of references private IdentityHashMap _refs; private Date date; private Calendar utcCalendar; private Calendar localCalendar; /** * Creates a new Burlap output stream, initialized with an * underlying output stream. * * @param os the underlying output stream. */ public BurlapOutput(OutputStream os) { init(os); } /** * Creates an uninitialized Burlap output stream. */ public BurlapOutput() { } /** * Initializes the output */ public void init(OutputStream os) { this.os = os; _refs = null; if (_serializerFactory == null) _serializerFactory = new SerializerFactory(); } /** * Writes a complete method call. */ public void call(String method, Object []args) throws IOException { startCall(method); if (args != null) { for (int i = 0; i < args.length; i++) writeObject(args[i]); } completeCall(); } /** * Starts the method call. Clients would use <code>startCall</code> * instead of <code>call</code> if they wanted finer control over * writing the arguments, or needed to write headers. * * <code><pre> * <burlap:call> * <method>method-name</method> * </pre></code> * * @param method the method name to call. */ public void startCall(String method) throws IOException { print("<burlap:call><method>"); print(method); print("</method>"); } /** * Starts the method call. Clients would use <code>startCall</code> * instead of <code>call</code> if they wanted finer control over * writing the arguments, or needed to write headers. * * <code><pre> * <method>method-name</method> * </pre></code> * * @param method the method name to call. */ public void startCall() throws IOException { print("<burlap:call>"); } /** * Writes the method for a call. * * <code><pre> * <method>value</method> * </pre></code> * * @param method the method name to call. */ public void writeMethod(String method) throws IOException { print("<method>"); print(method); print("</method>"); } /** * Completes. * * <code><pre> * </burlap:call> * </pre></code> */ public void completeCall() throws IOException { print("</burlap:call>"); } /** * Starts the reply * * <p>A successful completion will have a single value: * * <pre> * r * </pre> */ public void startReply() throws IOException { print("<burlap:reply>"); } /** * Completes reading the reply * * <p>A successful completion will have a single value: * * <pre> * </burlap:reply> * </pre> */ public void completeReply() throws IOException { print("</burlap:reply>"); } /** * Writes a header name. The header value must immediately follow. * * <code><pre> * <header>foo</header><int>value</int> * </pre></code> */ public void writeHeader(String name) throws IOException { print("<header>"); printString(name); print("</header>"); } /** * Writes a fault. The fault will be written * as a descriptive string followed by an object: * * <code><pre> * <fault> * <string>code * <string>the fault code * * <string>message * <string>the fault mesage * * <string>detail * <map>t\x00\xnnjavax.ejb.FinderException * ... * </map> * </fault> * </pre></code> * * @param code the fault code, a three digit */ public void writeFault(String code, String message, Object detail) throws IOException { print("<fault>"); writeString("code"); writeString(code); writeString("message"); writeString(message); if (detail != null) { writeString("detail"); writeObject(detail); } print("</fault>"); } /** * Writes any object to the output stream. */ public void writeObject(Object object) throws IOException { if (object == null) { writeNull(); return; } Serializer serializer; serializer = _serializerFactory.getSerializer(object.getClass()); serializer.writeObject(object, this); } /** * Writes the list header to the stream. List writers will call * <code>writeListBegin</code> followed by the list contents and then * call <code>writeListEnd</code>. * * <code><pre> * <list> * <type>java.util.ArrayList</type> * <length>3</length> * <int>1</int> * <int>2</int> * <int>3</int> * </list> * </pre></code> */ public boolean writeListBegin(int length, String type) throws IOException { print("<list><type>"); if (type != null) print(type); print("</type><length>"); print(length); print("</length>"); return true; } /** * Writes the tail of the list to the stream. */ public void writeListEnd() throws IOException { print("</list>"); } /** * Writes the map header to the stream. Map writers will call * <code>writeMapBegin</code> followed by the map contents and then * call <code>writeMapEnd</code>. * * <code><pre> * <map> * <type>type</type> * (<key> <value>)* * </map> * </pre></code> */ public void writeMapBegin(String type) throws IOException { print("<map><type>"); if (type != null) print(type); print("</type>"); } /** * Writes the tail of the map to the stream. */ public void writeMapEnd() throws IOException { print("</map>"); } /** * Writes a remote object reference to the stream. The type is the * type of the remote interface. * * <code><pre> * <remote> * <type>test.account.Account</type> * <string>http://caucho.com/foo;ejbid=bar</string> * </remote> * </pre></code> */ public void writeRemote(String type, String url) throws IOException { print("<remote><type>"); print(type); print("</type><string>"); print(url); print("</string></remote>"); } /** * Writes a boolean value to the stream. The boolean will be written * with the following syntax: * * <code><pre> * <boolean>0</boolean> * <boolean>1</boolean> * </pre></code> * * @param value the boolean value to write. */ public void writeBoolean(boolean value) throws IOException { if (value) print("<boolean>1</boolean>"); else print("<boolean>0</boolean>"); } /** * Writes an integer value to the stream. The integer will be written * with the following syntax: * * <code><pre> * <int>int value</int> * </pre></code> * * @param value the integer value to write. */ public void writeInt(int value) throws IOException { print("<int>"); print(value); print("</int>"); } /** * Writes a long value to the stream. The long will be written * with the following syntax: * * <code><pre> * <long>int value</long> * </pre></code> * * @param value the long value to write. */ public void writeLong(long value) throws IOException { print("<long>"); print(value); print("</long>"); } /** * Writes a double value to the stream. The double will be written * with the following syntax: * * <code><pre> * <double>value</double> * </pre></code> * * @param value the double value to write. */ public void writeDouble(double value) throws IOException { print("<double>"); print(value); print("</double>"); } /** * Writes a date to the stream. * * <code><pre> * <date>iso8901</date> * </pre></code> * * @param time the date in milliseconds from the epoch in UTC */ public void writeUTCDate(long time) throws IOException { print("<date>");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?