/[classpath]/classpath/gnu/CORBA/GIOP/MessageHeader.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/GIOP/MessageHeader.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.1 by gnu_andrew, Fri May 20 18:20:49 2005 UTC revision 1.1.2.2 by gnu_andrew, Sun Jun 5 19:36:36 2005 UTC
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package gnu.CORBA.GIOP;  package gnu.CORBA.GIOP;
40    
41    import gnu.CORBA.CDR.BigEndianOutputStream;
42    import gnu.CORBA.CDR.LittleEndianInputStream;
43    import gnu.CORBA.CDR.LittleEndianOutputStream;
44    import gnu.CORBA.CDR.abstractDataOutputStream;
45  import gnu.CORBA.Version;  import gnu.CORBA.Version;
46    
47    import org.omg.CORBA.MARSHAL;
48    import org.omg.CORBA.portable.IDLEntity;
49    
50  import java.io.DataInputStream;  import java.io.DataInputStream;
 import java.io.DataOutputStream;  
51  import java.io.IOException;  import java.io.IOException;
52    import java.io.OutputStream;
53    
54  import java.util.Arrays;  import java.util.Arrays;
55    import gnu.CORBA.CDR.BigEndianInputStream;
56  import org.omg.CORBA.MARSHAL;  import gnu.CORBA.CDR.abstractDataInputStream;
57  import org.omg.CORBA.portable.IDLEntity;  import java.io.InputStream;
58    
59  /**  /**
60   * The GIOP message header.   * The GIOP message header.
# Line 142  public class MessageHeader Line 149  public class MessageHeader
149     */     */
150    public MessageHeader()    public MessageHeader()
151    {    {
152      version = new Version(1,0);      version = new Version(1, 0);
153    }    }
154    
155    /**    /**
# Line 166  public class MessageHeader Line 173  public class MessageHeader
173    }    }
174    
175    /**    /**
176       * Set the encoding to use.
177       *
178       * @param use_big_endian if true (default), the Big Endian
179       * encoding is used. If false, the Little Endian encoding is used.
180       */
181      public void setBigEndian(boolean use_big_endian)
182      {
183        if (use_big_endian)
184          flags = (byte) (flags & ~1);
185        else
186          flags = (byte) (flags | 1);
187      }
188    
189      /**
190     * Get the size of the message header itself. So far, it is always 12 bytes.     * Get the size of the message header itself. So far, it is always 12 bytes.
191     */     */
192    public int getHeaderSize()    public int getHeaderSize()
# Line 250  public class MessageHeader Line 271  public class MessageHeader
271    {    {
272      try      try
273        {        {
         DataInputStream din = new DataInputStream(istream);  
   
274          byte[] xMagic = new byte[ MAGIC.length ];          byte[] xMagic = new byte[ MAGIC.length ];
275          din.read(xMagic);          istream.read(xMagic);
276          if (!Arrays.equals(xMagic, MAGIC))          if (!Arrays.equals(xMagic, MAGIC))
277            throw new MARSHAL("Not a GIOP message");            throw new MARSHAL("Not a GIOP message");
278    
279          version = Version.read_version(din);          version = Version.read_version(istream);
280    
281          flags = (byte) din.read();          abstractDataInputStream din;
282    
283          /** TODO implement support for the little endian. */          flags = (byte) istream.read();
284          if (!isBigEndian())  
285            throw new MARSHAL("Little endian unsupported.");          // This checks the bit in the byte we have just received.
286            if (isBigEndian())
287              din = new BigEndianInputStream(istream);
288            else
289              din = new LittleEndianInputStream(istream);
290    
291          message_type = (byte) din.read();          message_type = (byte) din.read();
292    
293          message_size = din.readInt();          message_size = din.readInt();
294        }        }
295      catch (IOException ex)      catch (IOException ex)
296        {        {
297          throw new MARSHAL(ex.toString());          MARSHAL t = new MARSHAL();
298            t.initCause(ex);
299            throw t;
300        }        }
301    }    }
302    
# Line 295  public class MessageHeader Line 321  public class MessageHeader
321    {    {
322      try      try
323        {        {
324          DataOutputStream dout = new DataOutputStream(out);          abstractDataOutputStream dout;
325    
326            if (isBigEndian())
327              dout = new BigEndianOutputStream(out);
328            else
329              dout = new LittleEndianOutputStream(out);
330    
331          // Write magic sequence.          // Write magic sequence.
332          dout.write(MAGIC);          dout.write(MAGIC);
333    
334          // Write version number.          // Write version number.
335          version.write(dout);          version.write((OutputStream) dout);
336    
337          dout.write(flags);          dout.write(flags);
338    
339          dout.write(message_type);          dout.write(message_type);
340    
341          dout.writeInt(message_size);          dout.writeInt(message_size);
342        }        }
343      catch (IOException ex)      catch (IOException ex)
344        {        {
345          throw new MARSHAL(ex.toString());          MARSHAL t = new MARSHAL();
346            t.initCause(ex);
347            throw t;
348        }        }
349    }    }
350  }  }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26