cdroutputstream_1_0.java

来自「JAVA 所有包」· Java 代码 · 共 1,932 行 · 第 1/4 页

JAVA
1,932
字号
    public void start_block() {        if (debug) {            dprint("CDROutputStream_1_0 start_block, position" + bbwi.position());	}        //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.position();        if (debug) {            dprint("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) {            dprint("CDROutputStream_1_0.java end_block");	}	if (!inBlock)	    return;        if (debug) {            dprint("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.position()?  REVISIT            bbwi.position(bbwi.position() - 4);	    blockSizeIndex = -1;            blockSizePosition = -1;	    return;	}	int oldSize = bbwi.position();	bbwi.position(blockSizeIndex - 4);        writeLongWithoutAlign(oldSize - blockSizeIndex);	bbwi.position(oldSize);	blockSizeIndex = -1;        blockSizePosition = -1;        // System.out.println("      post end_block: " + get_offset() + " " + bbwi.position());    }        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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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 wrapper.nullParam(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.    //    public void writeTo(java.io.OutputStream s) 	throws java.io.IOException     {        byte[] tmpBuf = null;        if (bbwi.byteBuffer.hasArray())        {            tmpBuf = bbwi.byteBuffer.array();        }        else        {            int size = bbwi.position();            tmpBuf = new byte[size];            // Micro-benchmarks are showing a loop of ByteBuffer.get(int) is            // faster than ByteBuffer.get(byte[], offset, length)            for (int i = 0; i < size; i++)                tmpBuf[i] = bbwi.byteBuffer.get(i);        }	s.write(tmpBuf, 0, bbwi.position());	    }    public void writeOctetSequenceTo(org.omg.CORBA.portable.OutputStream s) {        byte[] buf = null;        if (bbwi.byteBuffer.hasArray())        {            buf = bbwi.byteBuffer.array();        }        else        {            int size = bbwi.position();            buf = new byte[size];            // Micro-benchmarks are showing a loop of ByteBuffer.get(int) is            // faster than ByteBuffer.get(byte[], offset, length)            for (int i = 0; i < size; i++)                buf[i] = bbwi.byteBuffer.get(i);        }    	s.write_long(bbwi.position());    	s.write_octet_array(buf, 0, bbwi.position());    }    public final int getSize() {    	return bbwi.position();    }    public int getIndex() {    	return bbwi.position();    }    public boolean isLittleEndian() {        return littleEndian;    }    public void setIndex(int value) {        bbwi.position(value);    }    public ByteBufferWithInfo getByteBufferWithInfo() {        return bbwi;    }    public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {        this.bbwi = bbwi;    }    public ByteBuffer getByteBuffer() {        ByteBuffer result = null;;        if (bbwi != null) {            result = bbwi.byteBuffer;        }        return result;    }    public void setByteBuffer(ByteBuffer byteBuffer) {        bbwi.byteBuffer = byteBuffer;    }    private final void updateIndirectionTable(int indirection, java.lang.Object object,                                              java.lang.Object key) {	// int indirection = get_offset();	if (valueCache == null)	    valueCache = new CacheTable(orb,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.        int indirection = writeString(id);        // Add indirection for id to indirection table        if (repositoryIdCache == null)	repositoryIdCache = new CacheTable(orb,true);        repositoryIdCache.put(id, indirection);    }    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(orb,true);            codebaseCache.put(str, pos);        }    }    private final int writeValueTag(boolean chunkIt, boolean useRepId, 				    String codebase) {	int indirection = 0;	if (chunkIt && !useRepId){	    if (codebase == null) {		write_long(repIdUtil.getStandardRMIChunkedNoRepStrId());		indirection = get_offset() - 4;	    } else {					write_long(repIdUtil.getCodeBaseRMIChunkedNoRepStrId());		indirection = get_offset() - 4;		write_codebase(codebase, get_offset());	    }	} else if (chunkIt && useRepId){	    if (codebase == null) {		write_long(repIdUtil.getStandardRMIChunkedId());		indirection = get_offset() - 4;	    } else {					write_long(repIdUtil.getCodeBaseRMIChunkedId());		indirection = get_offset() - 4;		write_codebase(codebase, get_offset());	    }	} else if (!chunkIt && !useRepId) {	    if (codebase == null) {		write_long(repIdUtil.getStandardRMIUnchunkedNoRepStrId());		indirection = get_offset() - 4;	    } else {					write_long(repIdUtil.getCodeBaseRMIUnchunkedNoRepStrId());		indirection = get_offset() - 4;		write_codebase(codebase, get_offset());	    }	} else if (!chunkIt && useRepId) {	    if (codebase == null) {		write_long(repIdUtil.getStandardRMIUnchunkedId());		indirection = get_offset() - 4;	    } else {					write_long(repIdUtil.getCodeBaseRMIUnchunkedId());		indirection = get_offset() - 4;		write_codebase(codebase, get_offset());	    }	}        return indirection;    }    private void writeIDLValue(Serializable object, String repID)    {    	if (object instanceof StreamableValue) {	    ((StreamableValue)object)._write(parent);	} else if (object instanceof CustomValue) {	    ((CustomValue)object).marshal(parent);	} else {	    BoxedValueHelper helper = Utility.getHelper(object.getClass(), null, repID);	    boolean isCustom = false;	    if (helper instanceof ValueHelper && object instanceof CustomMarshal) {		try {		    if (((ValueHelper)helper).get_type().type_modifier() == VM_CUSTOM.value)		        isCustom = true;	        } catch(BadKind ex) {		    throw wrapper.badTypecodeForCustomValue( CompletionStatus.COMPLETED_MAYBE,			ex ) ;		}  	    }	    if (isCustom)		((CustomMarshal)object).marshal(parent);	    else		helper.write_value(parent, object);	}    }    // Handles end tag compaction...    private void writeEndTag(boolean chunked){			if (chunked) {	    if (get_offset() == end_flag_position) {                if (bbwi.position() == end_flag_index) {                    // We are exactly at the same position and index as the                    // end of the last end tag.  Thus, we can back up over it                    // and compact the tags.                    bbwi.position(bbwi.position() - 4);                } else {                    // Special case in which we're at the beginning of a new                    // fragment, but the position is the same.  We can't back up,                    // so we just write the new end tag without compaction.  This                    // occurs when a value ends and calls start_block to open a                    // continuation chunk, but it's called at the very end of                    // a fragment.                }            }            writeNestingLevel();            // Remember the last index and position.  These are only used when chunking.            end_flag_index = bbwi.position();            end_flag_position = get_offset();            chunkedValueNestingLevel++;        }        // Increment the nesting level	end_flag++;    }    /**     * Handles ORB versioning of the end tag.  Should only     * be called if chunking.     *     * If talking to our older ORBs (Standard Extension,     * Kestrel, and Ladybird), write the end flag that takes     * into account all enclosing valuetypes.     *     * If talking a newer or foreign ORB, or if the orb     * instance is null, write the end flag that only takes     * into account the enclosing chunked valuetypes.     */    private void writeNestingLevel() {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?