views:

250

answers:

1

I've got marshaled CDR data all by itself in the form of a file (i.e., not packed in a GIOP message) which I need to unmarshal and display on the screen. I get to know what type the data is and have working code to do this successfully by the following:

ValueFactory myFactory = (ValueFactory)myConstructor.newInstance( objParam );
StreamableValue myObject = myFactory.init();
myObject._read( myCDRInputStream );

where init() calls the constructor of myObjectImpl(). and _read is the org.omg.CORBA.portable.Streamable _read(InputStream) method.

This works as long as the marshaled data is of the same endianness as the computer running my reader program, but I will need to be able to handle cases where the endianness of the data is different than the endianness of the computer running the reader. I know that endianness is in GIOP messages, which I don't have. Assuming I figure out that I need to change the endianness, how can I tell this to the stream reader?

Thanks!

A: 

If you access to the underlying ByteBuffer of your input stream, and then you can set the endianness. For example I use this to open matlab files myself

    File file = new File("swiss_roll_data.matlab5");
    FileChannel channel = new FileInputStream(file).getChannel();
    ByteBuffer scan = channel.map(MapMode.READ_ONLY,0,channel.size());
    scan.order(ByteOrder.BIG_ENDIAN);

However, I dont know if you corba framework is happy to read from a bytebuffer (corba is so 90ies). So maybe that does not work for you.

Adrian
Thanks! It seems like the writer part I wrote in Java always writes in big endian, which might make my problem moot if I get word that the data coming in will always be created by Java programs, but I'm going to try to manually create a value in little endian format, modify my corba byte buffer's endianness to little endian, and let the CORBA _read method take a shot at correctly reading it.
Pete