idljavaserializationoutputstream.java

来自「JAVA 所有包」· Java 代码 · 共 781 行 · 第 1/2 页

JAVA
781
字号
	// is absent in GIOP version 1.2 or above.    	write_long(p.name().length);    	write_octet_array(p.name(), 0, p.name().length);    }        public final void write_fixed(java.math.BigDecimal bigDecimal) {        // This string might contain sign and/or dot        this.write_fixed(bigDecimal.toString(), bigDecimal.signum());    }    // The string may contain a sign and dot    private void write_fixed(String string, int signum) {        int stringLength = string.length();        // Each octet contains (up to) two decimal digits.        byte doubleDigit = 0;        char ch;        byte digit;        // First calculate the string length without optional sign and dot.        int numDigits = 0;        for (int i=0; i<stringLength; i++) {            ch = string.charAt(i);            if (ch == '-' || ch == '+' || ch == '.')                continue;            numDigits++;        }        for (int i=0; i<stringLength; i++) {            ch = string.charAt(i);            if (ch == '-' || ch == '+' || ch == '.')                continue;            digit = (byte)Character.digit(ch, 10);            if (digit == -1) {		throw wrapper.badDigitInFixed(					    CompletionStatus.COMPLETED_MAYBE);            }            // If the fixed type has an odd number of decimal digits, then the            // representation begins with the first (most significant) digit.            // Otherwise, this first half-octet is all zero, and the first            // digit is in the second half-octet.            if (numDigits % 2 == 0) {                doubleDigit |= digit;                this.write_octet(doubleDigit);                doubleDigit = 0;            } else {                doubleDigit |= (digit << 4);            }            numDigits--;        }        // The sign configuration in the last half-octet of the representation,        // is 0xD for negative numbers and 0xC for positive and zero values.        if (signum == -1) {            doubleDigit |= 0xd;        } else {            doubleDigit |= 0xc;        }        this.write_octet(doubleDigit);    }    public final org.omg.CORBA.ORB orb() {        return this.orb;    }    // org.omg.CORBA_2_3.portable.OutputStream    public final void write_value(java.io.Serializable value) {        write_value(value, (String) null);    }    public final void write_value(java.io.Serializable value,				  java.lang.Class clz) {	write_value(value);    }    public final void write_value(java.io.Serializable value,				  String repository_id) {	try {	    os.writeObject(value);	} catch (Exception e) {	    throw wrapper.javaSerializationException(e, "write_value");	}    }    public final void write_value(java.io.Serializable value,			     org.omg.CORBA.portable.BoxedValueHelper factory) {	this.write_value(value, (String) null);    }    public final void write_abstract_interface(java.lang.Object obj) {	boolean isCorbaObject = false; // Assume value type.	org.omg.CORBA.Object theCorbaObject = null;	    	// Is it a CORBA.Object?	if (obj != null && obj instanceof org.omg.CORBA.Object) {	    theCorbaObject = (org.omg.CORBA.Object)obj;	    isCorbaObject = true;	        	}	    	// Write the boolean flag.	this.write_boolean(isCorbaObject);	    	// Now write out the object.	if (isCorbaObject) {	    write_Object(theCorbaObject);	} 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());		}	    }	}    }    // com.sun.corba.se.os.encoding.MarshalOutputStream    public final void start_block() {	throw wrapper.giopVersionError();    }    public final void end_block() {	throw wrapper.giopVersionError();    }    public final void putEndian() {	throw wrapper.giopVersionError();    }    public void writeTo(java.io.OutputStream s)	throws IOException {	try {	    os.flush();	    bos.writeTo(s);	} catch (Exception e) {	    throw wrapper.javaSerializationException(e, "writeTo");	}    }    public final byte[] toByteArray() {	try {	    os.flush();	    return bos.toByteArray(); // new copy.	} catch (Exception e) {	    throw wrapper.javaSerializationException(e, "toByteArray");	}    }    // org.omg.CORBA.DataOutputStream    public final void write_Abstract (java.lang.Object value) {	write_abstract_interface(value);    }    public final void write_Value(java.io.Serializable value) {        write_value(value);    }    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]);	}    }    // org.omg.CORBA.portable.ValueBase    public final String[] _truncatable_ids() {	throw wrapper.giopVersionError();    }    // Other.    public final int getSize() {	try {	    os.flush();	    return bos.size();	} catch (Exception e) {	    throw wrapper.javaSerializationException(e, "write_boolean");	}    }    public final int getIndex() {        return getSize();    }    protected int getRealIndex(int index) {        return getSize();    }    public final void setIndex(int value) {	throw wrapper.giopVersionError();    }    public final ByteBuffer getByteBuffer() {	throw wrapper.giopVersionError();    }    public final void setByteBuffer(ByteBuffer byteBuffer) {	throw wrapper.giopVersionError();    }    public final boolean isLittleEndian() {	// Java serialization uses network byte order, that is, big-endian.	return false;     }    public ByteBufferWithInfo getByteBufferWithInfo() {	try {	    os.flush();	} catch (Exception e) {	    throw wrapper.javaSerializationException(					    e, "getByteBufferWithInfo");	}	ByteBuffer byteBuffer =	ByteBuffer.wrap(bos.getByteArray());	byteBuffer.limit(bos.size());	return new ByteBufferWithInfo(this.orb, byteBuffer, bos.size());    }    public void setByteBufferWithInfo(ByteBufferWithInfo bbwi) {	throw wrapper.giopVersionError();    }    public final BufferManagerWrite getBufferManager() {	return bufferManager;    }    // This will stay a custom add-on until the java-rtf issue is resolved.    // Then it should be declared in org.omg.CORBA.portable.OutputStream.    //    // Pads the string representation of bigDecimal with zeros to fit the given    // digits and scale before it gets written to the stream.    public final void write_fixed(java.math.BigDecimal bigDecimal,				  short digits, short scale) {        String string = bigDecimal.toString();        String integerPart;        String fractionPart;        StringBuffer stringBuffer;        // Get rid of the sign        if (string.charAt(0) == '-' || string.charAt(0) == '+') {            string = string.substring(1);        }        // Determine integer and fraction parts        int dotIndex = string.indexOf('.');        if (dotIndex == -1) {            integerPart = string;            fractionPart = null;        } else if (dotIndex == 0 ) {            integerPart = null;            fractionPart = string;        } else {            integerPart = string.substring(0, dotIndex);            fractionPart = string.substring(dotIndex + 1);        }        // Pad both parts with zeros as necessary        stringBuffer = new StringBuffer(digits);        if (fractionPart != null) {            stringBuffer.append(fractionPart);        }        while (stringBuffer.length() < scale) {            stringBuffer.append('0');        }        if (integerPart != null) {            stringBuffer.insert(0, integerPart);        }        while (stringBuffer.length() < digits) {            stringBuffer.insert(0, '0');        }        // This string contains no sign or dot        this.write_fixed(stringBuffer.toString(), bigDecimal.signum());    }    public final void writeOctetSequenceTo(	    org.omg.CORBA.portable.OutputStream s) {	byte[] buf = this.toByteArray(); // new copy.    	s.write_long(buf.length);     	s.write_octet_array(buf, 0, buf.length);    }    public final GIOPVersion getGIOPVersion() {	return GIOPVersion.V1_2;    }    public final void writeIndirection(int tag, int posIndirectedTo) {	throw wrapper.giopVersionError();    }    void freeInternalCaches() {}    void printBuffer() {	byte[] buf = this.toByteArray();        System.out.println("+++++++ Output Buffer ++++++++");        System.out.println();        System.out.println("Current position: " + buf.length);        //System.out.println("Total length : " + buf.length);        System.out.println();        char[] charBuf = new char[16];        try {            for (int i = 0; i < buf.length; i += 16) {                                int j = 0;                                // For every 16 bytes, there is one line                // of output.  First, the hex output of                // the 16 bytes with each byte separated                // by a space.                while (j < 16 && j + i < buf.length) {                    int k = buf[i + j];                    if (k < 0)                        k = 256 + k;                    String hex = Integer.toHexString(k);                    if (hex.length() == 1)                        hex = "0" + hex;                    System.out.print(hex + " ");                    j++;                }                                // Add any extra spaces to align the                // text column in case we didn't end                // at 16                while (j < 16) {                    System.out.print("   ");                    j++;                }                                // Now output the ASCII equivalents.  Non-ASCII                // characters are shown as periods.                int x = 0;                while (x < 16 && x + i < buf.length) {                    if (ORBUtility.isPrintable((char)buf[i + x])) {                        charBuf[x] = (char) buf[i + x];                    } else {                        charBuf[x] = '.';		    }                    x++;                }                System.out.println(new String(charBuf, 0, x));            }        } catch (Throwable t) {            t.printStackTrace();        }        System.out.println("++++++++++++++++++++++++++++++");    }    public void alignOnBoundary(int octetBoundary) {	throw wrapper.giopVersionError();    }    // Needed by request and reply messages for GIOP versions >= 1.2 only.    public void setHeaderPadding(boolean headerPadding) {	// no-op. We don't care about body alignment while using	// Java serialization. What the GIOP spec states does not apply here.    }    // ValueOutputStream -----------------------------    public void start_value(String rep_id) {	throw wrapper.giopVersionError();    }    public void end_value() {	throw wrapper.giopVersionError();    }    // java.io.OutputStream    // Note: These methods are defined in the super class and accessible.    //public abstract void write(byte b[]) throws IOException;    //public abstract void write(byte b[], int off, int len)     //    throws IOException;    //public abstract void flush() throws IOException;    //public abstract void close() throws IOException;}

⌨️ 快捷键说明

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