KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > giop > MessageOutputStream


1 package org.jacorb.orb.giop;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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 JavaDoc;
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.14 2004/05/06 12:40:00 nicolas Exp $
34  */

35
36 public class MessageOutputStream
37     extends CDROutputStream
38 {
39     public MessageOutputStream()
40     {
41         super( (org.omg.CORBA.ORB JavaDoc) null );
42     }
43
44     /**
45      * Writes a GIOPMessageHeader of the required type to the beginning of
46      * the buffer and sets the start position and index.
47      */

48
49     public void writeGIOPMsgHeader( int message_type,
50                                     int minor_version )
51     {
52         //attribute: magic (4 bytes)
53
buffer[0] = (byte) 'G';
54         buffer[1] = (byte) 'I';
55         buffer[2] = (byte) 'O';
56         buffer[3] = (byte) 'P';
57
58         //version
59
buffer[4] = 1; //GIOP major
60
buffer[5] = (byte) minor_version; //GIOP minor
61

62         //endianess in GIOP 1.0, flags in GIOP 1.1/1.2. Always use big
63
//endian.
64
//For 1.1/1.2: 2nd LSB is 1 for fragments, but this
65
//isn't supported (yet?) by JacORB. 6 MSBs must stay 0
66
buffer[6] = 0;
67
68         buffer[7] = (byte) message_type;
69
70         // Skip the header + leave 4 bytes for message size
71
skip( Messages.MSG_HEADER_SIZE );
72     }
73
74     public void insertMsgSize( int size )
75     {
76         //using big endian byte ordering
77
buffer[8] = (byte)((size >> 24) & 0xFF);
78         buffer[9] = (byte)((size >> 16) & 0xFF);
79         buffer[10] = (byte)((size >> 8) & 0xFF);
80         buffer[11] = (byte) (size & 0xFF);
81     }
82
83
84     public void insertMsgSize()
85     {
86         insertMsgSize( size() - Messages.MSG_HEADER_SIZE );
87     }
88
89     public void write_to( GIOPConnection conn )
90         throws IOException JavaDoc
91     {
92         insertMsgSize();
93
94         write( conn, 0, size() );
95
96         close();
97     }
98 }// MessageOutputStream
99
Popular Tags