📄 xmlobjectstreamunit.java
字号:
testDouble((double) -1029.2); testDouble((double) 17); testDouble((double) 182.29938); testFloat((float) 0); testFloat((float) 29.239); testFloat((float) 11.1029); testFloat((float) -1902.1); testLong(1920L); testLong(0L); testLong(192983783739892L); testLong(-1299L); testLong(-19282738339299L); testShort((short) 28); testShort((short) 1829); testShort((short) 0); testMultiplePrimitives(); test(new Integer(5)); test(new Long(2837L)); test(new Vector()); test("monkey"); test(""); test("blah blah balh\n blah blah ablh"); test("blah blah balh\n\t\r\n\r\t\r blah blah ablh"); test("<monkey>"); test("<>&;'\""); testHashtable(); testMultipleObjects(); testUnserializableObject(); testByteCustomSerializer(); testCustomSerializer(); testBrokenCustomSerializer(); testSerialPersistentFields(); testUnshared(); testExternal(); testSubExternal(); testPutFields(); testUnreadData(); testWriteReplace(); testReadResolve(); testInheritedWriteReplace(); testInheritedReadResolve(); test(new byte[7847]); test(new byte[4][6]); } /** * The main program for the XMLObjectStreamUnit class * * @param args The command line arguments * @exception IOException DESCRIBE THE EXCEPTION */ public static void main(String[] args) throws IOException { XMLObjectStreamUnit test = new XMLObjectStreamUnit(); test.start(); } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestByteSerialization implements Serializable { private transient byte[] bytes = new byte[]{23, 19, 49, 0}; /** * DESCRIBE THE METHOD * * @return DESCRIBE THE RETURN VALUE */ public byte[] bytes() { return bytes; } /** * DESCRIBE THE METHOD * * @param oos DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @exception ClassNotFoundException DESCRIBE THE EXCEPTION */ private void readObject(ObjectInputStream oos) throws IOException, ClassNotFoundException { bytes = new byte[5]; oos.read(bytes, 0, 5); } /** * DESCRIBE THE METHOD * * @param oos DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ private void writeObject(ObjectOutputStream oos) throws IOException { oos.write(bytes); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestExternalizable implements Externalizable { /** * DESCRIBE THE FIELD */ protected int num = 199; /** * Gets the Num attribute of the TestExternalizable object * * @return The Num value */ public int getNum() { return num; } /** * DESCRIBE THE METHOD * * @param o DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ public void writeExternal(ObjectOutput o) throws IOException { o.writeInt(num + 100); o.writeInt(2000); } /** * DESCRIBE THE METHOD * * @param i DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @exception ClassNotFoundException DESCRIBE THE EXCEPTION */ public void readExternal(ObjectInput i) throws IOException, ClassNotFoundException { num = i.readInt(); i.readInt(); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestSubExternalizable extends TestExternalizable { /** * Constructor for TestSubExternalizable. * * @param o DESCRIBE THE PARAMETER */ public TestSubExternalizable(Object o) { } /** * Constructor for TestSubExternalizable. */ private TestSubExternalizable() { } /** * DESCRIBE THE METHOD * * @param o DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ public void writeExternal(ObjectOutput o) throws IOException { super.writeExternal(o); o.writeInt(1000); } /** * DESCRIBE THE METHOD * * @param i DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @exception ClassNotFoundException DESCRIBE THE EXCEPTION */ public void readExternal(ObjectInput i) throws IOException, ClassNotFoundException { super.readExternal(i); num = i.readInt(); } /** * DESCRIBE THE METHOD * * @param ois DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @exception ClassNotFoundException DESCRIBE THE EXCEPTION */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { throw new IllegalArgumentException("READ OBJECT SHOULD NOT BE CALLED!"); } /** * DESCRIBE THE METHOD * * @param oos DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ private void writeObject(ObjectOutputStream oos) throws IOException { throw new IllegalArgumentException("WRITE OBJECT SHOULD NOT BE CALLED!"); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestPutFields implements Serializable { int num = 0; Integer num2 = null; /** * Gets the Num attribute of the TestPutFields object * * @return The Num value */ public int getNum() { return num; } /** * Gets the Num2 attribute of the TestPutFields object * * @return The Num2 value */ public int getNum2() { return num2.intValue(); } /** * DESCRIBE THE METHOD * * @param oos DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ private void writeObject(ObjectOutputStream oos) throws IOException { ObjectOutputStream.PutField pf = oos.putFields(); pf.put("num", 10001); pf.put("num2", new Integer(99)); pf.put("blah", 100); oos.writeFields(); } /** * DESCRIBE THE METHOD * * @param ois DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION * @exception ClassNotFoundException DESCRIBE THE EXCEPTION */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ObjectInputStream.GetField gf = ois.readFields(); num = gf.get("num", 0); num2 = (Integer) gf.get("num2", new Integer(0)); gf.get("blah", 0); if (!gf.defaulted("monkey")) { throw new IOException("Field monkey was not defaulted!"); } if (gf.defaulted("num")) { throw new IOException("Field num was defaulted!"); } if (gf.defaulted("num2")) { throw new IOException("Field num was defaulted!"); } } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestUnreadData implements Serializable { int num = 293; /** * Gets the Num attribute of the TestUnreadData object * * @return The Num value */ public int getNum() { return num; } /** * DESCRIBE THE METHOD * * @param oos DESCRIBE THE PARAMETER * @exception IOException DESCRIBE THE EXCEPTION */ private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); oos.writeInt(10); oos.writeObject("niondco"); oos.writeObject(new Vector()); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestReplace implements Serializable { /** * DESCRIBE THE METHOD * * @return DESCRIBE THE RETURN VALUE */ protected Object writeReplace() { return new TestReplace2(); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestReplace2 extends TestReplace { } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestReplace3 extends TestReplace { } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestResolve implements Serializable { /** * DESCRIBE THE METHOD * * @return DESCRIBE THE RETURN VALUE */ protected Object readResolve() { return new TestResolve2(); } } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestResolve2 extends TestResolve { } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestResolve3 extends TestResolve { } /** * DESCRIBE THE CLASS * * @version $Id: pretty.settings 2305 2005-03-11 20:22:33Z jeffh $ * @author jeffh */ public static class TestSerialPersistentFields implements Serializable { private Integer num1 = new Integer(1); private Integer num2 = new Integer(2); private final static ObjectStreamField[] serialPersistentFields = {new ObjectStreamField("num1", Integer.class)}; /** * Gets the Num1 attribute of the TestSerialPersistentFields object * * @return The Num1 value */ public Integer getNum1() { return num1; } /** * Gets the Num2 attribute of the TestSerialPersistentFields object * * @return The Num2 value */ public Integer getNum2() { return num2; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -