[Aglets-commits] aglets2.1/src/com/ibm/atp ContentBuffer.java,NONE,1.1 AtpConstants.java,NONE,1.1 Co
Status: Beta
Brought to you by:
cat4hire
Update of /cvsroot/aglets/aglets2.1/src/com/ibm/atp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7551/src/com/ibm/atp Added Files: ContentBuffer.java AtpConstants.java ContentBuffer.class AtpConstants.class ContentOutputStream.class ContentOutputStream.java Log Message: --- NEW FILE: AtpConstants.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: AtpConstants.java --- package com.ibm.atp; /* * @(#)AtpConstants.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */ /** * AtciConstants interface defines constant value for ATCI * * @version 1.10 23 Mar 1997 * @author Mitsuru Oshima */ public interface AtpConstants { static public final int REQUEST_TYPE_BASE = 1000; static public final int DISPATCH = REQUEST_TYPE_BASE + 1; static public final int RETRACT = REQUEST_TYPE_BASE + 2; static public final int FETCH = REQUEST_TYPE_BASE + 3; static public final int PING = REQUEST_TYPE_BASE + 4; static public final int MESSAGE = REQUEST_TYPE_BASE + 5; static public final int REPLY = REQUEST_TYPE_BASE + 6; static public final int ILLEGAL_REQUEST = REQUEST_TYPE_BASE + 7; static public final int MAX_REQUEST_TYPE = REQUEST_TYPE_BASE + 8; static public final int NO_AUTHENTICATION_MANNER = 0; static public final int AUTHENTICATION_MANNER_DIGEST = 1; static public final int AUTHENTICATION_MANNER_SIGNATURE = 2; /** * The value representing that an ATCI message is a response. */ public static final int ATCI_REQUEST = 1; /** * The value representing that an ATCI message is a response. */ public static final int ATCI_RESPONSE = 2; /** * Status code representing that the request has succeeded. */ public static final int OKAY = 100; /** * Status code representing that the requested resource is no longer at the * recipient. */ public static final int MOVED = 200; /** * Status code representing that the recipient was unable to understand the * request message due to malformed syntax. */ public static final int BAD_REQUEST = 300; /** * Status code representing that although the recipient understood the * request message, it is refused to fulfill it. */ public static final int FORBIDDEN = 301; /** * Status code representing that the recipient could not find the requested * resource. */ public static final int NOT_FOUND = 302; /** * Status code representing that the recipient encountered an unexpected * condition which prevented it from fullfiling the request. */ public static final int INTERNAL_ERROR = 400; /** * Status code representing that the recipient does not support the * functionality required to fulfill the request. */ public static final int NOT_IMPLEMENTED = 401; /** * Status code representing that the recipient, while acting as a gateway * or proxy, recieved an invalid response from upstream server. */ public static final int BAD_GATEWAY = 402; /** * Status code representing that the recipient is currently unable to * handle the request due to a temporary overloading of the recipient. */ public static final int SERVICE_UNAVAILABLE = 403; /** * Status code representing that the recipient does not authenticate * the sender. */ public static final int NOT_AUTHENTICATED = 500; /* * For Messaging */ public static final int SYNC = 0; public static final int FUTURE = 1; public static final int ONEWAY = 2; /* * */ public static final int HANDLED = 0; public static final int NOT_HANDLED = 1; public static final int EXCEPTION = 2; } --- NEW FILE: ContentBuffer.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ContentOutputStream.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ContentBuffer.java --- package com.ibm.atp; /* * @(#)ContentBuffer.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */ public interface ContentBuffer { public void sendContent() throws java.io.IOException; } --- NEW FILE: ContentOutputStream.java --- package com.ibm.atp; /* * @(#)ContentOutputStream.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */ import java.io.OutputStream; import java.io.PrintStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import com.ibm.awb.misc.Resource; /** * The content output stream writes a message content to the given output * stream. The content output stream creats MIME header fields, * combines it with a message body, and writes it into the specifid output * stream. * * @version 1.20 3 Mar 1997 * @author Danny B. Lange * @author Gaku Yamamoto * @author Mitsuru Oshima */ final public class ContentOutputStream extends ByteArrayOutputStream implements ContentBuffer { /** * A separator in the message's header. */ public static final String CRLF = "\r\n"; /** * An output stream into which ATP messages is written. An atp output * stream writes ATP messages into it. */ protected OutputStream _out = null; private boolean content_started = false; private boolean content_sent = false; private static int BUFFSIZE = 2048; int wrote = 0; byte buffer[]; static { Resource res = Resource.getResourceFor("atp"); BUFFSIZE = res.getInteger("atp.buffersize", 2048); } /** * Create a new instance of ContentOutputStream. * @param os an instance of OutputStream into which the instantiated atp * output stream writes. */ public ContentOutputStream(OutputStream os) { this(os, false); } public ContentOutputStream(OutputStream os, boolean started) { super(4096); _out = os; buffer = new byte[BUFFSIZE]; wrote = 0; content_started = started; } /** * Close the stream. This automatically flushe if the request has not * been sent. */ synchronized public void close() throws IOException { content_sent = true; flush(); _out.close(); } public void flush() throws IOException { if (content_sent) { _out.write(buf, 0, count); _out.flush(); reset(); } } synchronized public void sendContent() throws IOException { if (content_sent) { throw new IOException("Content has been already sent"); } content_sent = true; // _out.flush(); // _out = _tmp; String cl = CRLF; if (count != 0) { cl = "Content-Length:" + String.valueOf(count) + CRLF + CRLF; } else { // length unknown } byte ab[] = cl.getBytes(); if (wrote + ab.length < BUFFSIZE) { // store System.arraycopy(ab, 0, buffer, wrote, ab.length); wrote += ab.length; } else { // flush() _out.write(buffer, 0, wrote); wrote = 0; // write _out.write(ab, 0, ab.length); } if (wrote + count < BUFFSIZE) { System.arraycopy(buf, 0, buffer, wrote, count); wrote += count; _out.write(buffer, 0, wrote); } else { _out.write(buffer, 0, wrote); _out.write(buf, 0, count); } wrote = 0; _out.flush(); reset(); if (_out instanceof ContentBuffer) { ((ContentBuffer)_out).sendContent(); } } synchronized public void startContent() throws IOException { if (content_started) { throw new IOException("Content has been already started"); } content_started = true; if (count < BUFFSIZE) { // store System.arraycopy(buf, 0, buffer, 0, count); wrote = count; } else { _out.write(buf, 0, count); wrote = 0; } reset(); } } |