01: package org.jacorb.orb.giop;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1997-2004 Gerald Brose.
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: */
22:
23: import java.io.IOException;
24: import org.jacorb.orb.CDROutputStream;
25:
26: /**
27: * MessageOutputStream.java
28: *
29: *
30: * Created: Sat Aug 18 12:12:22 2002
31: *
32: * @author Nicolas Noffke
33: * @version $Id: MessageOutputStream.java,v 1.15 2006/05/12 14:39:53 alphonse.bendt Exp $
34: */
35:
36: public class MessageOutputStream extends CDROutputStream {
37: public MessageOutputStream() {
38: this ((org.omg.CORBA.ORB) null);
39: }
40:
41: public MessageOutputStream(org.omg.CORBA.ORB orb) {
42: super (orb);
43: }
44:
45: /**
46: * Writes a GIOPMessageHeader of the required type to the beginning of
47: * the buffer and sets the start position and index.
48: */
49:
50: public void writeGIOPMsgHeader(int message_type, int minor_version) {
51: //attribute: magic (4 bytes)
52: buffer[0] = (byte) 'G';
53: buffer[1] = (byte) 'I';
54: buffer[2] = (byte) 'O';
55: buffer[3] = (byte) 'P';
56:
57: //version
58: buffer[4] = 1; //GIOP major
59: buffer[5] = (byte) minor_version; //GIOP minor
60:
61: //endianess in GIOP 1.0, flags in GIOP 1.1/1.2. Always use big
62: //endian.
63: //For 1.1/1.2: 2nd LSB is 1 for fragments, but this
64: //isn't supported (yet?) by JacORB. 6 MSBs must stay 0
65: buffer[6] = 0;
66:
67: buffer[7] = (byte) message_type;
68:
69: // Skip the header + leave 4 bytes for message size
70: skip(Messages.MSG_HEADER_SIZE);
71: }
72:
73: public void insertMsgSize(int size) {
74: //using big endian byte ordering
75: buffer[8] = (byte) ((size >> 24) & 0xFF);
76: buffer[9] = (byte) ((size >> 16) & 0xFF);
77: buffer[10] = (byte) ((size >> 8) & 0xFF);
78: buffer[11] = (byte) (size & 0xFF);
79: }
80:
81: public void insertMsgSize() {
82: insertMsgSize(size() - Messages.MSG_HEADER_SIZE);
83: }
84:
85: public void write_to(GIOPConnection conn) throws IOException {
86: insertMsgSize();
87:
88: write(conn, 0, size());
89:
90: close();
91: }
92: }// MessageOutputStream
|