cdroutputstream_1_0.java
来自「JAVA 所有包」· Java 代码 · 共 1,932 行 · 第 1/4 页
JAVA
1,932 行
handleSpecialChunkBegin(computeAlignment(4) + 4 + len); write_long(len); int indirection = get_offset() - 4; internalWriteOctetArray(converter.getBytes(), 0, converter.getNumBytes()); // Write the null ending write_octet((byte)0); handleSpecialChunkEnd(); return indirection; } public void write_wstring(String value) { if (value == null) throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); // Don't allow transmission of wchar/wstring data with // foreign ORBs since it's against the spec. if (ORBUtility.isForeignORB(orb)) { throw wrapper.wcharDataInGiop10(CompletionStatus.COMPLETED_MAYBE); } // When talking to our legacy ORBs, do what they did: int len = value.length() + 1; // This will only have an effect if we're already chunking handleSpecialChunkBegin(4 + (len * 2) + computeAlignment(4)); write_long(len); for (int i = 0; i < len - 1; i++) write_wchar(value.charAt(i)); // Write the null ending write_short((short)0); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } // Performs no checks and doesn't tamper with chunking void internalWriteOctetArray(byte[] value, int offset, int length) { int n = offset; // This flag forces the alignAndReserve method to be called the // first time an octet is written. This is necessary to ensure // that the body is aligned on an 8-octet boundary. Note the 'if' // condition inside the 'while' loop below. Also, refer to the // write_octet() method that has a similar change. boolean align = true; while (n < length+offset) { int avail; int bytes; int wanted; if ((bbwi.position() + 1 > bbwi.buflen) || align) { align = false; alignAndReserve(1, 1); } avail = bbwi.buflen - bbwi.position(); wanted = (length + offset) - n; bytes = (wanted < avail) ? wanted : avail; for (int i = 0; i < bytes; i++) bbwi.byteBuffer.put(bbwi.position() + i, value[n+i]); bbwi.position(bbwi.position() + bytes); n += bytes; } } public final void write_octet_array(byte b[], int offset, int length) { if ( b == null ) throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(length); internalWriteOctetArray(b, offset, length); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public void write_Principal(Principal p) { write_long(p.name().length); write_octet_array(p.name(), 0, p.name().length); } public void write_any(Any any) { if ( any == null ) throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); write_TypeCode(any.type()); any.write_value(parent); } public void write_TypeCode(TypeCode tc) { if ( tc == null ) { throw wrapper.nullParam(CompletionStatus.COMPLETED_MAYBE); } TypeCodeImpl tci; if (tc instanceof TypeCodeImpl) { tci = (TypeCodeImpl)tc; } else { tci = new TypeCodeImpl(orb, tc); } tci.write_value((org.omg.CORBA_2_3.portable.OutputStream)parent); } public void write_Object(org.omg.CORBA.Object ref) { if (ref == null) { IOR nullIOR = IORFactories.makeIOR( orb ) ; nullIOR.write(parent); return; } // IDL to Java formal 01-06-06 1.21.4.2 if (ref instanceof org.omg.CORBA.LocalObject) throw wrapper.writeLocalObject(CompletionStatus.COMPLETED_MAYBE); IOR ior = ORBUtility.connectAndGetIOR( orb, ref ) ; ior.write(parent); return; } // ------------ RMI related methods -------------------------- public void write_abstract_interface(java.lang.Object obj) { boolean corbaObject = false; // Assume value type. org.omg.CORBA.Object theObject = null; // Is it a CORBA.Object? if (obj != null && obj instanceof org.omg.CORBA.Object) { // Yes. theObject = (org.omg.CORBA.Object)obj; corbaObject = true; } // Write our flag... write_boolean(corbaObject); // Now write out the object... if (corbaObject) { write_Object(theObject); } else { try { write_value((java.io.Serializable)obj); } catch(ClassCastException cce) { if (obj instanceof java.io.Serializable) throw cce; else ORBUtility.throwNotSerializableForCorba(obj.getClass().getName()); } } } public void write_value(Serializable object, Class clz) { write_value(object); } private void writeWStringValue(String string) { int indirection = writeValueTag(mustChunk, true, null); // Write WStringValue's repository ID write_repositoryId(repIdStrs.getWStringValueRepId()); // Add indirection for object to indirection table updateIndirectionTable(indirection, string, string); // Write Value chunk if (mustChunk) { start_block(); end_flag--; chunkedValueNestingLevel--; } else end_flag--; write_wstring(string); if (mustChunk) end_block(); // Write end tag writeEndTag(mustChunk); } private void writeArray(Serializable array, Class clazz) { if (valueHandler == null) valueHandler = ORBUtility.createValueHandler(orb); //d11638 // Write value_tag int indirection = writeValueTag(mustChunk, true, Util.getCodebase(clazz)); // Write repository ID write_repositoryId(repIdStrs.createSequenceRepID(clazz)); // Add indirection for object to indirection table updateIndirectionTable(indirection, array, array); // Write Value chunk if (mustChunk) { start_block(); end_flag--; chunkedValueNestingLevel--; } else end_flag--; if (valueHandler instanceof ValueHandlerMultiFormat) { ValueHandlerMultiFormat vh = (ValueHandlerMultiFormat)valueHandler; vh.writeValue(parent, array, streamFormatVersion); } else valueHandler.writeValue(parent, array); if (mustChunk) end_block(); // Write end tag writeEndTag(mustChunk); } private void writeValueBase(org.omg.CORBA.portable.ValueBase object, Class clazz) { // _REVISIT_ could check to see whether chunking really needed mustChunk = true; // Write value_tag int indirection = writeValueTag(true, true, Util.getCodebase(clazz)); // Get rep id String repId = ((ValueBase)object)._truncatable_ids()[0]; // Write rep id write_repositoryId(repId); // Add indirection for object to indirection table updateIndirectionTable(indirection, object, object); // Write Value chunk start_block(); end_flag--; chunkedValueNestingLevel--; writeIDLValue(object, repId); end_block(); // Write end tag writeEndTag(true); } private void writeRMIIIOPValueType(Serializable object, Class clazz) { if (valueHandler == null) valueHandler = ORBUtility.createValueHandler(orb); //d11638 Serializable key = object; // Allow the ValueHandler to call writeReplace on // the Serializable (if the method is present) object = valueHandler.writeReplace(key); if (object == null) { // Write null tag and return write_long(0); return; } if (object != key) { if (valueCache != null && valueCache.containsKey(object)) { writeIndirection(INDIRECTION_TAG, valueCache.getVal(object)); return; } clazz = object.getClass(); } if (mustChunk || valueHandler.isCustomMarshaled(clazz)) { mustChunk = true; } // Write value_tag int indirection = writeValueTag(mustChunk, true, Util.getCodebase(clazz)); // Write rep. id write_repositoryId(repIdStrs.createForJavaType(clazz)); // Add indirection for object to indirection table updateIndirectionTable(indirection, object, key); if (mustChunk) { // Write Value chunk end_flag--; chunkedValueNestingLevel--; start_block(); } else end_flag--; if (valueHandler instanceof ValueHandlerMultiFormat) { ValueHandlerMultiFormat vh = (ValueHandlerMultiFormat)valueHandler; vh.writeValue(parent, object, streamFormatVersion); } else valueHandler.writeValue(parent, object); if (mustChunk) end_block(); // Write end tag writeEndTag(mustChunk); } public void write_value(Serializable object, String repository_id) { // Handle null references if (object == null) { // Write null tag and return write_long(0); return; } // Handle shared references if (valueCache != null && valueCache.containsKey(object)) { writeIndirection(INDIRECTION_TAG, valueCache.getVal(object)); return; } Class clazz = object.getClass(); boolean oldMustChunk = mustChunk; if (mustChunk) mustChunk = true; if (inBlock) end_block(); if (clazz.isArray()) { // Handle arrays writeArray(object, clazz); } else if (object instanceof org.omg.CORBA.portable.ValueBase) { // Handle IDL Value types writeValueBase((org.omg.CORBA.portable.ValueBase)object, clazz); } else if (shouldWriteAsIDLEntity(object)) { writeIDLEntity((IDLEntity)object); } else if (object instanceof java.lang.String) { writeWStringValue((String)object); } else if (object instanceof java.lang.Class) { writeClass(repository_id, (Class)object); } else { // RMI-IIOP value type writeRMIIIOPValueType(object, clazz); } mustChunk = oldMustChunk; // Check to see if we need to start another block for a // possible outer value if (mustChunk) start_block(); } public void write_value(Serializable object) { write_value(object, (String)null); } public void write_value(Serializable object, org.omg.CORBA.portable.BoxedValueHelper factory) { // Handle null references if (object == null) { // Write null tag and return write_long(0); return; } // Handle shared references if ((valueCache != null) && valueCache.containsKey(object)) { writeIndirection(INDIRECTION_TAG, valueCache.getVal(object)); return; } boolean oldMustChunk = mustChunk; boolean isCustom = false; if (factory instanceof ValueHelper) { short modifier; try { modifier = ((ValueHelper)factory).get_type().type_modifier(); } catch(BadKind ex) { // tk_value_box modifier = VM_NONE.value; } if (object instanceof CustomMarshal && modifier == VM_CUSTOM.value) { isCustom = true; mustChunk = true; } if (modifier == VM_TRUNCATABLE.value) mustChunk = true; } if (mustChunk) { if (inBlock) end_block(); // Write value_tag int indirection = writeValueTag(true, orb.getORBData().useRepId(), Util.getCodebase(object.getClass()) ); if (orb.getORBData().useRepId()) { write_repositoryId(factory.get_id()); } // Add indirection for object to indirection table updateIndirectionTable(indirection, object, object); // Write Value chunk start_block(); end_flag--; chunkedValueNestingLevel--; if (isCustom) ((CustomMarshal)object).marshal(parent); else factory.write_value(parent, object); end_block(); // Write end tag writeEndTag(true); } else { // Write value_tag int indirection = writeValueTag(false, orb.getORBData().useRepId(), Util.getCodebase(object.getClass()) ); if (orb.getORBData().useRepId()) { write_repositoryId(factory.get_id()); } // Add indirection for object to indirection table updateIndirectionTable(indirection, object, object); // Write Value chunk end_flag--; // no need to test for custom on the non-chunked path factory.write_value(parent, object); // Write end tag writeEndTag(false); } mustChunk = oldMustChunk; // Check to see if we need to start another block for a // possible outer value if (mustChunk) start_block(); } public int get_offset() { return bbwi.position(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?