001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.iiop;
030:
031: import java.io.IOException;
032:
033: abstract public class MessageWriter {
034: /**
035: * Starts a 1.0 message.
036: */
037: public void start10Message(int type) {
038: }
039:
040: /**
041: * Starts a 1.1 message.
042: */
043: public void start11Message(int type) {
044: }
045:
046: /**
047: * Starts a 1.2 message.
048: */
049: public void start12Message(int type) {
050: }
051:
052: /**
053: * Returns the offset.
054: */
055: abstract public int getOffset();
056:
057: /**
058: * Writes a byte.
059: */
060: abstract public void write(int v);
061:
062: /**
063: * Writes data
064: */
065: abstract public void write(byte[] buffer, int offset, int length);
066:
067: /**
068: * Writes a short
069: */
070: public void writeShort(int v) {
071: write(v >> 8);
072: write(v);
073: }
074:
075: /**
076: * Writes a char
077: */
078: public void writeChar(char v) {
079: write(v >> 8);
080: write(v);
081: }
082:
083: /**
084: * Writes an integer.
085: */
086: public void writeInt(int v) {
087: write(v >> 24);
088: write(v >> 16);
089: write(v >> 8);
090: write(v);
091: }
092:
093: /**
094: * Writes a long.
095: */
096: public void writeLong(long v) {
097: write((int) (v >> 56));
098: write((int) (v >> 48));
099: write((int) (v >> 40));
100: write((int) (v >> 32));
101:
102: write((int) (v >> 24));
103: write((int) (v >> 16));
104: write((int) (v >> 8));
105: write((int) v);
106: }
107:
108: /**
109: * Aligns to a specified value.
110: */
111: public void align(int v) {
112: int offset = getOffset();
113:
114: while (offset % v != 0) {
115: offset++;
116: write(0);
117: }
118: }
119:
120: /**
121: * Completes the response.
122: */
123: abstract public void close() throws IOException;
124: }
|