⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectstreamclass.java

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ObjectStreamClass.java -- Class used to write class information   about serialized objects.   Copyright (C) 1998, 1999, 2000, 2001, 2003  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.io;import java.lang.reflect.Constructor;import java.lang.reflect.Field;import java.lang.reflect.Member;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.lang.reflect.Proxy;import java.security.DigestOutputStream;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.security.Security;import java.util.Arrays;import java.util.Comparator;import java.util.Hashtable;import java.util.Vector;import gnu.java.io.NullOutputStream;import gnu.java.lang.reflect.TypeSignature;import gnu.java.security.provider.Gnu;public class ObjectStreamClass implements Serializable{  /**     Returns the <code>ObjectStreamClass</code> for <code>cl</code>.     If <code>cl</code> is null, or is not <code>Serializable</code>,     null is returned.  <code>ObjectStreamClass</code>'s are memorized;     later calls to this method with the same class will return the     same <code>ObjectStreamClass</code> object and no recalculation     will be done.     @see java.io.Serializable  */  public static ObjectStreamClass lookup (Class cl)  {    if (cl == null)      return null;    if (! (Serializable.class).isAssignableFrom (cl))      return null;    return lookupForClassObject (cl);  }  /**   * This lookup for internal use by ObjectOutputStream.  Suppose   * we have a java.lang.Class object C for class A, though A is not   * serializable, but it's okay to serialize C.   */  static ObjectStreamClass lookupForClassObject (Class cl)  {    if (cl == null)      return null;    ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);    if (osc != null)      return osc;    else    {      osc = new ObjectStreamClass (cl);      classLookupTable.put (cl, osc);      return osc;    }  }  /**     Returns the name of the class that this     <code>ObjectStreamClass</code> represents.  */  public String getName ()  {    return name;  }  /**     Returns the class that this <code>ObjectStreamClass</code>     represents.  Null could be returned if this     <code>ObjectStreamClass</code> was read from an     <code>ObjectInputStream</code> and the class it represents cannot     be found or loaded.     @see java.io.ObjectInputStream  */  public Class forClass ()  {    return clazz;  }  /**     Returns the serial version stream-unique identifier for the class     represented by this <code>ObjectStreamClass</code>.  This SUID is     either defined by the class as <code>static final long     serialVersionUID</code> or is calculated as specified in     Javasoft's "Object Serialization Specification" XXX: add reference  */  public long getSerialVersionUID ()  {    return uid;  }  // Returns the serializable (non-static and non-transient) Fields  // of the class represented by this ObjectStreamClass.  The Fields  // are sorted by name.  // XXX doc  public ObjectStreamField[] getFields ()  {    ObjectStreamField[] copy = new ObjectStreamField[ fields.length ];    System.arraycopy (fields, 0, copy, 0, fields.length);    return copy;  }  // XXX doc  // Can't do binary search since fields is sorted by name and  // primitiveness.  public ObjectStreamField getField (String name)  {    for (int i=0; i < fields.length; i++)      if (fields[i].getName ().equals (name))	return fields[i];    return null;  }  /**     Returns a textual representation of this     <code>ObjectStreamClass</code> object including the name of the     class it represents as well as that class's serial version     stream-unique identifier.     @see getSerialVersionUID ()     @see getName ()  */  public String toString ()  {    return "java.io.ObjectStreamClass< " + name + ", " + uid + " >";  }  // Returns true iff the class that this ObjectStreamClass represents  // has the following method:  //  // private void writeObject (ObjectOutputStream)  //  // This method is used by the class to override default  // serialization behavior.  boolean hasWriteMethod ()  {    return (flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0;  }  // Returns true iff the class that this ObjectStreamClass represents  // has the following method:  //  // private void readObject (ObjectOutputStream)  //  // This method is used by the class to override default  // serialization behavior.  boolean hasReadMethod ()  {      try      {	  Class[] readObjectParams = { ObjectInputStream.class };	  forClass ().getDeclaredMethod ("readObject", readObjectParams);	  return true;      }      catch (NoSuchMethodException e)      {	  return false;      }  }  // Returns true iff the class that this ObjectStreamClass represents  // implements Serializable but does *not* implement Externalizable.  boolean isSerializable ()  {    return (flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0;  }  // Returns true iff the class that this ObjectStreamClass represents  // implements Externalizable.  boolean isExternalizable ()  {    return (flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0;  }  // Returns the <code>ObjectStreamClass</code> that represents the  // class that is the superclass of the class this  // <code>ObjectStreamClass</code> represents.  If the superclass is  // not Serializable, null is returned.  ObjectStreamClass getSuper ()  {    return superClass;  }  // returns an array of ObjectStreamClasses that represent the super  // classes of CLAZZ and CLAZZ itself in order from most super to  // CLAZZ.  ObjectStreamClass[0] is the highest superclass of CLAZZ  // that is serializable.  static ObjectStreamClass[] getObjectStreamClasses (Class clazz)  {    ObjectStreamClass osc = ObjectStreamClass.lookup (clazz);    ObjectStreamClass[] ret_val;    if (osc == null)      return new ObjectStreamClass[0];    else    {      Vector oscs = new Vector ();      while (osc != null)      {	oscs.addElement (osc);	osc = osc.getSuper ();      }      int count = oscs.size ();      ObjectStreamClass[] sorted_oscs = new ObjectStreamClass[ count ];      for (int i = count - 1; i >= 0; i--)	sorted_oscs[ count - i - 1 ] = (ObjectStreamClass)oscs.elementAt (i);      return sorted_oscs;    }  }  // Returns an integer that consists of bit-flags that indicate  // properties of the class represented by this ObjectStreamClass.  // The bit-flags that could be present are those defined in  // ObjectStreamConstants that begin with `SC_'  int getFlags ()  {    return flags;  }  ObjectStreamClass (String name, long uid, byte flags,		     ObjectStreamField[] fields)  {    this.name = name;    this.uid = uid;    this.flags = flags;    this.fields = fields;  }  void setClass (Class cl) throws InvalidClassException  {    this.clazz = cl;    long class_uid = getClassUID (cl);    if (uid == 0)      uid = class_uid;    else      {	// Check that the actual UID of the resolved class matches the UID from 	// the stream.    	if (uid != class_uid)	  {	    String msg = cl + 	      ": Local class not compatible: stream serialVersionUID="	      + uid + ", local serialVersionUID=" + class_uid;	    throw new InvalidClassException (msg);	  }      }    isProxyClass = clazz != null && Proxy.isProxyClass (clazz);    ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (clazz);    if (osc == null)      classLookupTable.put (clazz, this);    superClass = lookupForClassObject (clazz.getSuperclass ());    calculateOffsets ();  }  void setSuperclass (ObjectStreamClass osc)  {    superClass = osc;  }  void calculateOffsets ()  {    int i;    ObjectStreamField field;    primFieldSize = 0;    int fcount = fields.length;    for (i = 0; i < fcount; ++ i)    {      field = fields[i];      if (! field.isPrimitive ())	break;      field.setOffset (primFieldSize);      switch (field.getTypeCode ())      {	case 'B':	case 'Z':	  ++ primFieldSize;	  break;

⌨️ 快捷键说明

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