FileDocCategorySizeDatePackage
EncapsulationUtility.javaAPI DocJava SE 5 API3582Fri Aug 26 14:54:22 BST 2005com.sun.corba.se.impl.ior

EncapsulationUtility

public class EncapsulationUtility extends Object
This static utility class contains various utility methods for reading and writing CDR encapsulations.
author
Ken Cavanaugh

Fields Summary
Constructors Summary
private EncapsulationUtility()

    
Methods Summary
public static org.omg.CORBA_2_3.portable.InputStreamgetEncapsulationStream(org.omg.CORBA_2_3.portable.InputStream is)
Helper method to read the octet array from is, deencapsulate it, and return as another InputStream. This must be called inside the constructor of a derived class to obtain the correct stream for unmarshalling data.

	byte[] data = readOctets( is ) ;
	EncapsInputStream result = new EncapsInputStream( is.orb(), data, 
	    data.length ) ;
	result.consumeEndian() ;
	return result ;
    
public static voidreadIdentifiableSequence(java.util.List container, com.sun.corba.se.spi.ior.IdentifiableFactoryFinder finder, org.omg.CORBA_2_3.portable.InputStream istr)
Read the count from is, then read count Identifiables from is using the factory. Add each constructed Identifiable to container.

	int count = istr.read_long() ;
	for (int ctr = 0; ctr<count; ctr++) {
	    int id = istr.read_long() ;
	    Identifiable obj = finder.create( id, istr ) ;
	    container.add( obj ) ;
	}
    
public static byte[]readOctets(org.omg.CORBA_2_3.portable.InputStream is)
Helper method that reads an octet array from an input stream. Defined as static here so that it can be used in another class.

	int len = is.read_ulong() ;
	byte[] data = new byte[len] ;
	is.read_octet_array( data, 0, len ) ;
	return data ;
    
public static voidwriteEncapsulation(com.sun.corba.se.spi.ior.WriteContents obj, org.omg.CORBA_2_3.portable.OutputStream os)

	EncapsOutputStream out = new EncapsOutputStream( (ORB)os.orb() ) ;

	out.putEndian() ;

	obj.writeContents( out ) ;

	writeOutputStream( out, os ) ;
    
public static voidwriteIdentifiableSequence(java.util.List container, org.omg.CORBA_2_3.portable.OutputStream os)
Write all Identifiables that we contain to os. The total length must be written before this method is called.

	os.write_long( container.size() ) ;
	Iterator iter = container.iterator() ;
	while (iter.hasNext()) {
	    Identifiable obj = (Identifiable)( iter.next() ) ;
	    os.write_long( obj.getId() ) ;
	    obj.write( os ) ;
	}
    
public static voidwriteOutputStream(org.omg.CORBA_2_3.portable.OutputStream dataStream, org.omg.CORBA_2_3.portable.OutputStream os)
Helper method that is used to extract data from an output stream and write the data to another output stream. Defined as static so that it can be used in another class.

	byte[] data = ((CDROutputStream)dataStream).toByteArray() ;
	os.write_long( data.length ) ;
	os.write_octet_array( data, 0, data.length ) ;