microburlapoutput.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 695 行 · 第 1/2 页
JAVA
695 行
/* * The Apache Software License, Version 1.1 * * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved. * * 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.client;import java.io.IOException;import java.io.OutputStream;import java.util.Calendar;import java.util.Date;import java.util.Enumeration;import java.util.Hashtable;import java.util.TimeZone;import java.util.Vector;/** * Output stream for Burlap requests, compatible with microedition * Java. It only uses classes and types available to J2ME. In * particular, it does not have any support for the <double> type. * * <p>MicroBurlapOutput does not depend on any classes other than * in J2ME, so it can be extracted independently into a smaller package. * * <p>MicroBurlapOutput is unbuffered, so any client needs to provide * its own buffering. * * <pre> * OutputStream os = ...; // from http connection * MicroBurlapOutput out = new MicroBurlapOutput(os); * String value; * * out.startCall("hello"); // start hello call * out.writeString("arg1"); // write a string argument * out.completeCall(); // complete the call * </pre> */public class MicroBurlapOutput { private OutputStream os; 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 MicroBurlapOutput(OutputStream os) { init(os); } /** * Creates an uninitialized Burlap output stream. */ public MicroBurlapOutput() { } public void init(OutputStream os) { this.os = os; } /** * 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(); } /** * Writes the method call: * * <code><pre> * <burlap:request> * <method>add</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>"); } /** * Writes the method call: * * <code><pre> * </burlap:request> * </pre></code> */ public void completeCall() throws IOException { print("</burlap:call>"); } /** * Writes a boolean value to the stream. The boolean will be written * with the following syntax: * * <code><pre> * <boolean>1</boolean> * </pre></code> * * @param value the boolean value to write. */ public void writeBoolean(boolean value) throws IOException { print("<boolean>"); printInt(value ? 1 : 0); print("</boolean>"); } /** * Writes an integer value to the stream. The integer will be written * with the following syntax: * * <code><pre> * <int>123</int> * </pre></code> * * @param value the integer value to write. */ public void writeInt(int value) throws IOException { print("<int>"); printInt(value); print("</int>"); } /** * Writes a long value to the stream. The long will be written * with the following syntax: * * <code><pre> * <long>123</long> * </pre></code> * * @param value the long value to write. */ public void writeLong(long value) throws IOException { print("<long>"); printLong(value); print("</long>"); } /** * Writes a null value to the stream. * The null will be written with the following syntax * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeNull() throws IOException { print("<null></null>"); } /** * Writes a string value to the stream using UTF-8 encoding. * The string will be written with the following syntax: * * <code><pre> * <string>12.3e10</string> * </pre></code> * * If the value is null, it will be written as * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeString(String value) throws IOException { if (value == null) { print("<null></null>"); } else { print("<string>"); printString(value); print("</string>"); } } /** * Writes a byte array to the stream using base64 encoding. * The array will be written with the following syntax: * * <code><pre> * <base64>dJmO==</base64> * </pre></code> * * If the value is null, it will be written as * * <code><pre> * <null></null> * </pre></code> * * @param value the string value to write. */ public void writeBytes(byte []buffer, int offset, int length) throws IOException { if (buffer == null) { print("<null></null>"); } else { print("<base64>"); printBytes(buffer, offset, length); print("</base64>"); } } /** * Writes a date to the stream using ISO8609. * * <code><pre> * <date>19980508T095131Z</date> * </pre></code> * * @param value the date in milliseconds from the epoch in UTC */ public void writeUTCDate(long time) throws IOException { print("<date>"); if (utcCalendar == null) { utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); date = new Date(); } date.setTime(time); utcCalendar.setTime(date); printDate(utcCalendar); print("</date>"); } /** * Writes a date to the stream using ISO8609. * * <code><pre> * <date>19980508T095131Z</date> * </pre></code> * * @param value the date in milliseconds from the epoch in local timezone */ public void writeLocalDate(long time) throws IOException { print("<date>"); if (localCalendar == null) { localCalendar = Calendar.getInstance(); date = new Date(); } date.setTime(time); localCalendar.setTime(date); printDate(localCalendar); print("</date>"); } /** * Writes a reference. * * <code><pre> * <ref>123</ref> * </pre></code> * * @param value the integer value to write. */ public void writeRef(int value) throws IOException { print("<ref>"); printInt(value);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?