1 7 8 package com.sun.corba.se.impl.ior; 9 10 import java.util.List ; 11 import java.util.LinkedList ; 12 import java.util.Iterator ; 13 14 import org.omg.IOP.TAG_INTERNET_IOP ; 15 16 import org.omg.CORBA_2_3.portable.OutputStream ; 17 import org.omg.CORBA_2_3.portable.InputStream ; 18 19 import com.sun.corba.se.spi.ior.TaggedComponent ; 20 import com.sun.corba.se.spi.ior.Identifiable ; 21 import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; 22 import com.sun.corba.se.spi.ior.WriteContents ; 23 24 import com.sun.corba.se.spi.orb.ORB ; 25 26 import com.sun.corba.se.impl.ior.FreezableList ; 27 28 import com.sun.corba.se.impl.encoding.CDROutputStream ; 29 import com.sun.corba.se.impl.encoding.EncapsOutputStream ; 30 import com.sun.corba.se.impl.encoding.EncapsInputStream ; 31 32 38 public class EncapsulationUtility 39 { 40 private EncapsulationUtility() 41 { 42 } 43 44 47 public static void readIdentifiableSequence( List container, 48 IdentifiableFactoryFinder finder, InputStream istr) 49 { 50 int count = istr.read_long() ; 51 for (int ctr = 0; ctr<count; ctr++) { 52 int id = istr.read_long() ; 53 Identifiable obj = finder.create( id, istr ) ; 54 container.add( obj ) ; 55 } 56 } 57 58 61 public static void writeIdentifiableSequence( List container, OutputStream os) 62 { 63 os.write_long( container.size() ) ; 64 Iterator iter = container.iterator() ; 65 while (iter.hasNext()) { 66 Identifiable obj = (Identifiable)( iter.next() ) ; 67 os.write_long( obj.getId() ) ; 68 obj.write( os ) ; 69 } 70 } 71 72 76 static public void writeOutputStream( OutputStream dataStream, 77 OutputStream os ) 78 { 79 byte[] data = ((CDROutputStream)dataStream).toByteArray() ; 80 os.write_long( data.length ) ; 81 os.write_octet_array( data, 0, data.length ) ; 82 } 83 84 90 static public InputStream getEncapsulationStream( InputStream is ) 91 { 92 byte[] data = readOctets( is ) ; 93 EncapsInputStream result = new EncapsInputStream( is.orb(), data, 94 data.length ) ; 95 result.consumeEndian() ; 96 return result ; 97 } 98 99 102 static public byte[] readOctets( InputStream is ) 103 { 104 int len = is.read_ulong() ; 105 byte[] data = new byte[len] ; 106 is.read_octet_array( data, 0, len ) ; 107 return data ; 108 } 109 110 static public void writeEncapsulation( WriteContents obj, 111 OutputStream os ) 112 { 113 EncapsOutputStream out = new EncapsOutputStream( (ORB)os.orb() ) ; 114 115 out.putEndian() ; 116 117 obj.writeContents( out ) ; 118 119 writeOutputStream( out, os ) ; 120 } 121 } 122 | Popular Tags |