cdroutputstream_1_0.java
来自「java jdk 1.4的源码」· Java 代码 · 共 2,001 行 · 第 1/4 页
JAVA
2,001 行
writeEndTag(false); } } else if (object instanceof java.lang.Class) { writeClass(repIdStrs.getClassDescValueRepId(), (Class)object); } else // Not a CORBA Value Type { if (valueHandler == null) valueHandler = ORBUtility.createValueHandler(orb); //d11638 Serializable key = object; 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(true, false, Util.getCodebase(clazz)); // Write rep. id write_repositoryId(repIdStrs.createForJavaType(clazz)); // Add indirection for object to indirection table updateIndirectionTable(indirection, object, key); // Write Value chunk end_flag--; chunkedValueNestingLevel--; start_block(); valueHandler.writeValue(parent, object); end_block(); // Write end tag writeEndTag(true); } else { // Write value_tag int indirection = writeValueTag(false, false, Util.getCodebase(clazz)); // Write rep. id write_repositoryId(repIdStrs.createForJavaType(clazz)); // Add indirection for object to indirection table updateIndirectionTable(indirection, object, key); // Write Value chunk end_flag--; valueHandler.writeValue(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 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, false, Util.getCodebase(object.getClass())); 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, false, Util.getCodebase(object.getClass())); 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.index; } public void start_block() { if (debug) debugPrintMessage("CDROutputStream_1_0 start_block, index" + bbwi.index); //Move inBlock=true to after write_long since write_long might //trigger grow which will lead to erroneous behavior with a //missing blockSizeIndex. //inBlock = true; // Save space in the buffer for block size write_long(0); //Has to happen after write_long since write_long could //trigger grow which is overridden by supper classes to //depend on inBlock. inBlock = true; blockSizePosition = get_offset(); // Remember where to put the size of the endblock less 4 blockSizeIndex = bbwi.index; if (debug) debugPrintMessage("CDROutputStream_1_0 start_block, blockSizeIndex " + blockSizeIndex); } // Utility method which will hopefully decrease chunking complexity // by allowing us to end_block and update chunk lengths without // calling alignAndReserve. Otherwise, it's possible to get into // recursive scenarios which lose the chunking state. protected void writeLongWithoutAlign(int x) { if (littleEndian) { writeLittleEndianLong(x); } else { writeBigEndianLong(x); } } public void end_block() { if (debug) debugPrintMessage("CDROutputStream_1_0.java end_block"); if (!inBlock) return; if (debug) debugPrintMessage("CDROutputStream_1_0.java end_block, in a block"); inBlock = false; // Test to see if the block was of zero length // If so, remove the block instead of ending it // (This can happen if the last field written // in a value was another value) if (get_offset() == blockSizePosition) { // Need to assert that blockSizeIndex == bbwi.index? REVISIT bbwi.index = bbwi.index - 4; blockSizeIndex = -1; blockSizePosition = -1; return; } int oldSize = bbwi.index; bbwi.index = blockSizeIndex - 4; writeLongWithoutAlign(oldSize - blockSizeIndex); bbwi.index = oldSize; blockSizeIndex = -1; blockSizePosition = -1; // System.out.println(" post end_block: " + get_offset() + " " + bbwi.index); } public org.omg.CORBA.ORB orb() { return orb; } // ------------ End RMI related methods -------------------------- public final void write_boolean_array(boolean[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(length); for (int i = 0; i < length; i++) write_boolean(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_char_array(char[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(length); for (int i = 0; i < length; i++) write_char(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public void write_wchar_array(char[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(2) + (length * 2)); for (int i = 0; i < length; i++) write_wchar(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_short_array(short[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(2) + (length * 2)); for (int i = 0; i < length; i++) write_short(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_ushort_array(short[]value, int offset, int length) { write_short_array(value, offset, length); } public final void write_long_array(int[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(4) + (length * 4)); for (int i = 0; i < length; i++) write_long(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_ulong_array(int[]value, int offset, int length) { write_long_array(value, offset, length); } public final void write_longlong_array(long[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(8) + (length * 8)); for (int i = 0; i < length; i++) write_longlong(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_ulonglong_array(long[]value, int offset, int length) { write_longlong_array(value, offset, length); } public final void write_float_array(float[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(4) + (length * 4)); for (int i = 0; i < length; i++) write_float(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public final void write_double_array(double[]value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(com.sun.corba.se.internal.orbutil.MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); // This will only have an effect if we're already chunking handleSpecialChunkBegin(computeAlignment(8) + (length * 8)); for (int i = 0; i < length; i++) write_double(value[offset + i]); // This will only have an effect if we're already chunking handleSpecialChunkEnd(); } public void write_string_array(String[] value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); for(int i = 0; i < length; i++) write_string(value[offset + i]); } public void write_wstring_array(String[] value, int offset, int length) { if ( value == null ) throw new BAD_PARAM(MinorCodes.NULL_PARAM, CompletionStatus.COMPLETED_MAYBE); for(int i = 0; i < length; i++) write_wstring(value[offset + i]); } public final void write_any_array(org.omg.CORBA.Any value[], int offset, int length) { for(int i = 0; i < length; i++) write_any(value[offset + i]); } //--------------------------------------------------------------------// // CDROutputStream state management. // /** * Write the contents of the CDROutputStream to the specified output stream. * @param s The output stream to write to. */ public void writeTo(java.io.OutputStream s) throws java.io.IOException { s.write(bbwi.buf, 0, bbwi.index); } public void writeOctetSequenceTo(org.omg.CORBA.portable.OutputStream s) { s.write_long(bbwi.index); s.write_octet_array(bbwi.buf, 0, bbwi.index); } public final int getSize() { return bbwi.index; } public int getIndex() { return bbwi.index; } public boolean isLittleEndian() { return littleEndian; } public void setIndex(int value) { bbwi.index = value; } public ByteBufferWithInfo getByteBufferWithInfo() { return bbwi; } public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) { this.bbwi = bbwi; } public byte[] getByteBuffer() { return bbwi.buf; } public void setByteBuffer(byte[] value) { bbwi.buf = value; } private final void updateIndirectionTable(int indirection, java.lang.Object object, java.lang.Object key) { // int indirection = get_offset(); if (valueCache == null) valueCache = new CacheTable(true); valueCache.put(object, indirection); if (key != object) valueCache.put(key, indirection); } private final void write_repositoryId(String id) { // Use an indirection if available if (repositoryIdCache != null && repositoryIdCache.containsKey(id)) { writeIndirection(INDIRECTION_TAG, repositoryIdCache.getVal(id)); return; } // Write it as a string. Note that we have already done the // special case conversion of non-Latin-1 characters to escaped // Latin-1 sequences in RepositoryId. // It's not a good idea to cache them now that we can have // multiple code sets. write_string(id); } private void write_codebase(String str, int pos) { if (codebaseCache != null && codebaseCache.containsKey(str)) { writeIndirection(INDIRECTION_TAG, codebaseCache.getVal(str)); } else { write_string(str); if (codebaseCache == null) codebaseCache = new CacheTable(true); codebaseCache.put(str, pos); } } private final int writeValueTag(boolean chunkIt, boolean repNotWritten, String codebase) { int indirection = 0; if (chunkIt && repNotWritten){ if (codebase == null) { write_long(repIdUtil.getStandardRMIChunkedNoRepStrId()); indirection = get_offset() - 4; } else { write_long(repIdUtil.getCodeBaseRMIChunkedNoRepStrId());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?