下面列出了怎么用org.omg.CORBA.portable.InputStream的API类实例代码及写法,或者点击链接到github查看源代码。
public org.omg.CORBA.Object resolve( String identifier )
{
InputStream inStream = null ;
org.omg.CORBA.Object result = null ;
try {
inStream = invoke( "get", identifier ) ;
result = inStream.read_Object();
// NOTE: do note trap and ignore errors.
// Let them flow out.
} finally {
bootstrapDelegate.releaseReply( null, inStream ) ;
}
return result ;
}
/**
* returns an input stream that an Any value can be marshaled out of.
*
* @result the InputStream to marshal value of Any out of.
*/
public org.omg.CORBA.portable.InputStream create_input_stream()
{
//
// We create a new InputStream so that multiple threads can call here
// and read the streams in parallel without thread safety problems.
//
//debug.log ("create_input_stream");
if (AnyImpl.isStreamed[realType().kind().value()]) {
return stream.dup();
} else {
OutputStream os = (OutputStream)orb.create_output_stream();
TCUtility.marshalIn(os, realType(), value, object);
return os.create_input_stream();
}
}
public org.omg.CORBA.Object resolve( String identifier )
{
InputStream inStream = null ;
org.omg.CORBA.Object result = null ;
try {
inStream = invoke( "get", identifier ) ;
result = inStream.read_Object();
// NOTE: do note trap and ignore errors.
// Let them flow out.
} finally {
bootstrapDelegate.releaseReply( null, inStream ) ;
}
return result ;
}
private CorbaObjectHandler getAnyContainedType(Any a) {
CorbaObjectHandler result = null;
TypeCode tc = a.type();
QName containedName = new QName("AnyContainedType");
QName idlType = null;
if (CorbaUtils.isPrimitiveTypeCode(tc)) {
idlType = CorbaAnyHelper.getPrimitiveIdlTypeFromTypeCode(tc);
result = new CorbaPrimitiveHandler(containedName, idlType, tc, null);
} else if (tc.kind().value() == TCKind._tk_any) {
idlType = CorbaConstants.NT_CORBA_ANY;
result = new CorbaAnyHandler(containedName, idlType, tc, null);
((CorbaAnyHandler)result).setTypeMap(handler.getTypeMap());
} else {
idlType = handler.getTypeMap().getIdlType(tc);
result = CorbaHandlerUtils.initializeObjectHandler(orb, containedName, idlType,
handler.getTypeMap(), serviceInfo);
}
InputStream is = a.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(is);
reader.read(result);
return result;
}
public java.util.Set list()
{
InputStream inStream = null ;
java.util.Set result = new java.util.HashSet() ;
try {
inStream = invoke( "list", null ) ;
int count = inStream.read_long();
for (int i=0; i < count; i++)
result.add( inStream.read_string() ) ;
// NOTE: do note trap and ignore errors.
// Let them flow out.
} finally {
bootstrapDelegate.releaseReply( null, inStream ) ;
}
return result ;
}
public java.util.Set list()
{
InputStream inStream = null ;
java.util.Set result = new java.util.HashSet() ;
try {
inStream = invoke( "list", null ) ;
int count = inStream.read_long();
for (int i=0; i < count; i++)
result.add( inStream.read_string() ) ;
// NOTE: do note trap and ignore errors.
// Let them flow out.
} finally {
bootstrapDelegate.releaseReply( null, inStream ) ;
}
return result ;
}
/**
* returns an input stream that an Any value can be marshaled out of.
*
* @result the InputStream to marshal value of Any out of.
*/
public org.omg.CORBA.portable.InputStream create_input_stream()
{
//
// We create a new InputStream so that multiple threads can call here
// and read the streams in parallel without thread safety problems.
//
//debug.log ("create_input_stream");
if (AnyImpl.isStreamed[realType().kind().value()]) {
return stream.dup();
} else {
OutputStream os = (OutputStream)orb.create_output_stream();
TCUtility.marshalIn(os, realType(), value, object);
return os.create_input_stream();
}
}
/**
* Read an object reference from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readObjectAndNarrow(InputStream in,
Class narrowTo)
throws ClassCastException
{
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
/** overrides create_input_stream from CDROutputStream */
public org.omg.CORBA.portable.InputStream create_input_stream()
{
// XREVISIT
return null;
//return new XIIOPInputStream(orb(), getByteBuffer(), getIndex(),
//isLittleEndian(), getMessageHeader(), conn);
}
public Any extractAny(TypeCode memberType, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream)stream, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
protected boolean initializeComponentsFromAny() {
// This typeCode is of kind tk_array.
TypeCode typeCode = any.type();
int length = getBound();
TypeCode contentType = getContentType();
InputStream input;
try {
input = any.create_input_stream();
} catch (BAD_OPERATION e) {
return false;
}
components = new DynAny[length];
anys = new Any[length];
for (int i=0; i<length; i++) {
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
// but only for primitive types
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
try {
// Creates the appropriate subtype without copying the Any
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
} catch (InconsistentTypeCode itc) { // impossible
}
}
return true;
}
public Any extractAny(TypeCode memberType, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream)stream, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
/**
* Reads a java.lang.Object as a CORBA any.
* @param in the stream from which to read the any.
* @return the object read from the stream.
*/
public Object readAny(InputStream in)
{
Any any = in.read_any();
if ( any.type().kind().value() == TCKind._tk_objref )
return any.extract_Object ();
else
return any.extract_Value();
}
@Test
public void testReadOctet() {
OutputStream oStream = orb.create_output_stream();
oStream.write_octet((byte)27);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
Byte octetValue = reader.readOctet();
assertTrue(octetValue.byteValue() == (byte)27);
}
@Test
public void testReadFloat() {
OutputStream oStream = orb.create_output_stream();
oStream.write_float((float)1234.56);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
Float floatValue = reader.readFloat();
assertTrue(floatValue.floatValue() == (float)1234.56);
}
static public Any extractAnyFromStream(TypeCode memberType, InputStream input, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy(input, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
public InputStream invoke(org.omg.CORBA.Object self, OutputStream output)
throws
ApplicationException,
RemarshalException
{
ClientRequestDispatcher subcontract = getClientRequestDispatcher();
return (InputStream)
subcontract.marshalingComplete((Object)self, (OutputObject)output);
}
/**
* Read an object reference from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readObjectAndNarrow(InputStream in,
Class narrowTo)
throws ClassCastException
{
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
public static SystemException extractSystemException(Any any) {
InputStream in = any.create_input_stream();
ORB orb = (ORB)(in.orb());
if ( ! isSystemExceptionTypeCode(any.type(), orb)) {
throw wrapper.unknownDsiSysex(CompletionStatus.COMPLETED_MAYBE);
}
return ORBUtility.readSystemException(in);
}
protected boolean initializeComponentsFromAny() {
// This typeCode is of kind tk_array.
TypeCode typeCode = any.type();
int length = getBound();
TypeCode contentType = getContentType();
InputStream input;
try {
input = any.create_input_stream();
} catch (BAD_OPERATION e) {
return false;
}
components = new DynAny[length];
anys = new Any[length];
for (int i=0; i<length; i++) {
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
// but only for primitive types
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
try {
// Creates the appropriate subtype without copying the Any
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
} catch (InconsistentTypeCode itc) { // impossible
}
}
return true;
}
public static SystemException extractSystemException(Any any) {
InputStream in = any.create_input_stream();
ORB orb = (ORB)(in.orb());
if ( ! isSystemExceptionTypeCode(any.type(), orb)) {
throw wrapper.unknownDsiSysex(CompletionStatus.COMPLETED_MAYBE);
}
return ORBUtility.readSystemException(in);
}
public void unmarshalReply(InputStream is)
{
// First unmarshal the return value if it is not void
if ( _result != null ) {
Any returnAny = _result.value();
TypeCode returnType = returnAny.type();
if ( returnType.kind().value() != TCKind._tk_void )
returnAny.read_value(is, returnType);
}
// Now unmarshal the out/inout args
try {
for ( int i=0; i<_arguments.count() ; i++) {
NamedValue nv = _arguments.item(i);
switch( nv.flags() ) {
case ARG_IN.value:
break;
case ARG_OUT.value:
case ARG_INOUT.value:
Any any = nv.value();
any.read_value(is, any.type());
break;
}
}
}
catch ( org.omg.CORBA.Bounds ex ) {
// Cannot happen since we only iterate till _arguments.count()
}
}
public Any extractAny(TypeCode memberType, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream)stream, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
/**
* Read an object reference from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readObjectAndNarrow(InputStream in,
Class narrowTo)
throws ClassCastException
{
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
/**
* Read an abstract interface type from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readAbstractAndNarrow(
org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
throws ClassCastException
{
Object result = in.read_abstract_interface();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
/** Read the data into a (presumably) empty ORTImpl. This sets the
* orb to the ORB of the InputStream.
*/
public void _read( InputStream is )
{
org.omg.CORBA_2_3.portable.InputStream istr =
(org.omg.CORBA_2_3.portable.InputStream)is ;
iorTemplate = IORFactories.makeIORTemplate( istr ) ;
orb = (ORB)(istr.orb()) ;
}
/**
* Read an abstract interface type from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readAbstractAndNarrow(
org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
throws ClassCastException
{
Object result = in.read_abstract_interface();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
@Test
public void testReadULong() {
OutputStream oStream = orb.create_output_stream();
oStream.write_ulong(100000);
InputStream iStream = oStream.create_input_stream();
CorbaObjectReader reader = new CorbaObjectReader(iStream);
long ulongValue = reader.readULong();
assertTrue(ulongValue == 100000);
}
public Any extractAny(TypeCode memberType, ORB orb) {
Any returnValue = orb.create_any();
OutputStream out = returnValue.create_output_stream();
TypeCodeImpl.convertToNative(orb, memberType).copy((InputStream)stream, out);
returnValue.read_value(out.create_input_stream(), memberType);
return returnValue;
}
protected boolean initializeComponentsFromAny() {
// This typeCode is of kind tk_array.
TypeCode typeCode = any.type();
int length = getBound();
TypeCode contentType = getContentType();
InputStream input;
try {
input = any.create_input_stream();
} catch (BAD_OPERATION e) {
return false;
}
components = new DynAny[length];
anys = new Any[length];
for (int i=0; i<length; i++) {
// _REVISIT_ Could use read_xxx_array() methods on InputStream for efficiency
// but only for primitive types
anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb);
try {
// Creates the appropriate subtype without copying the Any
components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false);
} catch (InconsistentTypeCode itc) { // impossible
}
}
return true;
}