📄 objectinputstream.java
字号:
field_name = real_field.getName (); } if (set_value && !default_initialize) { int comp_val = real_field.compareTo (stream_field); if (comp_val < 0) { default_initialize = true; real_idx++; } else if (comp_val > 0) { set_value = false; stream_idx++; } else { real_idx++; stream_idx++; } } try { if (type == Boolean.TYPE) { boolean value = default_initialize ? false : this.realInputStream.readBoolean (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setBooleanField (obj, stream_osc.forClass (), field_name, value); } else if (type == Byte.TYPE) { byte value = default_initialize ? 0 : this.realInputStream.readByte (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setByteField (obj, stream_osc.forClass (), field_name, value); } else if (type == Character.TYPE) { char value = default_initialize ? (char)0 : this.realInputStream.readChar (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setCharField (obj, stream_osc.forClass (), field_name, value); } else if (type == Double.TYPE) { double value = default_initialize ? 0 : this.realInputStream.readDouble (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setDoubleField (obj, stream_osc.forClass (), field_name, value); } else if (type == Float.TYPE) { float value = default_initialize ? 0 : this.realInputStream.readFloat (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setFloatField (obj, stream_osc.forClass (), field_name, value); } else if (type == Integer.TYPE) { int value = default_initialize ? 0 : this.realInputStream.readInt (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setIntField (obj, stream_osc.forClass (), field_name, value); } else if (type == Long.TYPE) { long value = default_initialize ? 0 : this.realInputStream.readLong (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setLongField (obj, stream_osc.forClass (), field_name, value); } else if (type == Short.TYPE) { short value = default_initialize ? (short)0 : this.realInputStream.readShort (); if (!default_initialize && set_value) dumpElementln (" " + field_name + ": " + value); if (set_value) setShortField (obj, stream_osc.forClass (), field_name, value); } else { Object value = default_initialize ? null : readObject (); if (set_value) setObjectField (obj, stream_osc.forClass (), field_name, real_field.getTypeString (), value); } } catch (NoSuchFieldError e) { dumpElementln("XXXX " + field_name + " does not exist."); } } } // Toggles writing primitive data to block-data buffer. private boolean setBlockDataMode (boolean on) { boolean oldmode = this.readDataFromBlock; this.readDataFromBlock = on; if (on) this.dataInputStream = this.blockDataInput; else this.dataInputStream = this.realInputStream; return oldmode; } // returns a new instance of REAL_CLASS that has been constructed // only to the level of CONSTRUCTOR_CLASS (a super class of REAL_CLASS) private Object newObject (Class real_class, Class constructor_class) { try { Object obj = allocateObject (real_class); callConstructor (constructor_class, obj); return obj; } catch (InstantiationException e) { return null; } } // runs all registered ObjectInputValidations in prioritized order // on OBJ private void invokeValidators () throws InvalidObjectException { Object[] validators = new Object[this.validators.size ()]; this.validators.copyInto (validators); Arrays.sort (validators); try { for (int i=0; i < validators.length; i++) ((ObjectInputValidation)validators[i]).validateObject (); } finally { this.validators.removeAllElements (); } } // this native method is used to get access to the protected method // of the same name in SecurityManger private static ClassLoader currentClassLoader (SecurityManager sm) { // FIXME: This is too simple. return ClassLoader.getSystemClassLoader (); } private static Field getField (Class klass, String name) throws java.lang.NoSuchFieldException { return klass.getDeclaredField(name); } private static Method getMethod (Class klass, String name, Class args[]) throws java.lang.NoSuchMethodException { return klass.getDeclaredMethod(name, args); } private void callReadMethod (Object obj, ObjectStreamClass osc) throws IOException { Class klass = osc.forClass(); try { Class classArgs[] = {ObjectInputStream.class}; Method m = getMethod (klass, "readObject", classArgs); if (m == null) return; Object args[] = {this}; m.invoke (obj, args); } catch (InvocationTargetException x) { /* Rethrow if possible. */ Throwable exception = x.getTargetException(); if (exception instanceof RuntimeException) throw (RuntimeException) exception; if (exception instanceof IOException) throw (IOException) exception; throw new IOException ("Exception thrown from readObject() on " + klass + ": " + exception.getClass().getName()); } catch (Exception x) { throw new IOException ("Failure invoking readObject() on " + klass + ": " + x.getClass().getName()); } } private native Object allocateObject (Class clazz) throws InstantiationException; private native void callConstructor (Class clazz, Object obj); private void setBooleanField (Object obj, Class klass, String field_name, boolean val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setBoolean (obj, val); } catch (Exception _) { } } private void setByteField (Object obj, Class klass, String field_name, byte val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setByte (obj, val); } catch (Exception _) { } } private void setCharField (Object obj, Class klass, String field_name, char val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setChar (obj, val); } catch (Exception _) { } } private void setDoubleField (Object obj, Class klass, String field_name, double val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setDouble (obj, val); } catch (Exception _) { } } private void setFloatField (Object obj, Class klass, String field_name, float val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setFloat (obj, val); } catch (Exception _) { } } private void setIntField (Object obj, Class klass, String field_name, int val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setInt (obj, val); } catch (Exception _) { } } private void setLongField (Object obj, Class klass, String field_name, long val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setLong (obj, val); } catch (Exception _) { } } private void setShortField (Object obj, Class klass, String field_name, short val) { try { Field f = getField (klass, field_name); f.setAccessible(true); f.setShort (obj, val); } catch (Exception _) { } } private void setObjectField (Object obj, Class klass, String field_name, String type_code, Object val) { try { Field f = getField (klass, field_name); f.setAccessible(true); // FIXME: We should check the type_code here f.set (obj, val); } catch (Exception _) { } } private static final int BUFFER_SIZE = 1024; private static final Class[] readObjectParams = { ObjectInputStream.class }; private DataInputStream realInputStream; private DataInputStream dataInputStream; private DataInputStream blockDataInput; private int blockDataPosition; private int blockDataBytes; private byte[] blockData; private boolean useSubclassMethod; private int nextOID; private boolean resolveEnabled; private Hashtable objectLookupTable; private Object currentObject; private ObjectStreamClass currentObjectStreamClass; private boolean readDataFromBlock; private boolean isDeserializing; private boolean fieldsAlreadyRead; private Vector validators; private static boolean dump; private void dumpElement (String msg) { if (Configuration.DEBUG && dump) System.out.print(msg); } private void dumpElementln (String msg) { if (Configuration.DEBUG && dump) System.out.println(msg); } static { if (Configuration.INIT_LOAD_LIBRARY) { System.loadLibrary ("javaio"); } }}// used to keep a prioritized list of object validatorsclass ValidatorAndPriority implements Comparable{ int priority; ObjectInputValidation validator; ValidatorAndPriority (ObjectInputValidation validator, int priority) { this.priority = priority; this.validator = validator; } public int compareTo (Object o) { ValidatorAndPriority vap = (ValidatorAndPriority)o; return this.priority - vap.priority; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -