Package java.io

Examples of java.io.ObjectStreamClass$OSCThreadLocalCache


public class Test implements Testlet
{
  public void testLookup (Class cl, boolean is_null)
  {
    ObjectStreamClass osc = ObjectStreamClass.lookup (cl);
    harness.check (is_null ? osc == null : osc != null);
  }
View Full Code Here


    {
      throw new WicketNotSerializableException(
          toPrettyPrintedStack(obj.getClass().getName()), exception);
    }

    ObjectStreamClass desc;
    for (;;)
    {
      try
      {
        desc = (ObjectStreamClass)LOOKUP_METHOD.invoke(null, new Object[] { cls,
            Boolean.TRUE });
        Class repCl;
        if (!((Boolean)HAS_WRITE_REPLACE_METHOD_METHOD.invoke(desc, null)).booleanValue() ||
            (obj = INVOKE_WRITE_REPLACE_METHOD.invoke(desc, new Object[] { obj })) == null ||
            (repCl = obj.getClass()) == cls)
        {
          break;
        }
        cls = repCl;
      }
      catch (IllegalAccessException e)
      {
        throw new RuntimeException(e);
      }
      catch (InvocationTargetException e)
      {
        throw new RuntimeException(e);
      }
    }

    if (cls.isPrimitive())
    {
      // skip
    }
    else if (cls.isArray())
    {
      checked.put(obj, null);
      Class ccl = cls.getComponentType();
      if (!(ccl.isPrimitive()))
      {
        Object[] objs = (Object[])obj;
        for (int i = 0; i < objs.length; i++)
        {
          String arrayPos = "[" + i + "]";
          simpleName = arrayPos;
          fieldDescription += arrayPos;
          check(objs[i]);
        }
      }
    }
    else if (obj instanceof Externalizable && (!Proxy.isProxyClass(cls)))
    {
      Externalizable extObj = (Externalizable)obj;
      try
      {
        extObj.writeExternal(new ObjectOutputAdaptor()
        {
          private int count = 0;

          public void writeObject(Object streamObj) throws IOException
          {
            // Check for circular reference.
            if (checked.containsKey(streamObj))
            {
              return;
            }

            checked.put(streamObj, null);
            String arrayPos = "[write:" + count++ + "]";
            simpleName = arrayPos;
            fieldDescription += arrayPos;

            check(streamObj);
          }
        });
      }
      catch (Exception e)
      {
        if (e instanceof WicketNotSerializableException)
        {
          throw (WicketNotSerializableException)e;
        }
        log.warn("error delegating to Externalizable : " + e.getMessage() + ", path: " +
            currentPath());
      }
    }
    else
    {
      Method writeObjectMethod = null;
      Object o = writeObjectMethodCache.get(cls);
      if (o != null)
      {
        if (o instanceof Method)
        {
          writeObjectMethod = (Method)o;
        }
      }
      else
      {
        try
        {
          writeObjectMethod = cls.getDeclaredMethod("writeObject",
              new Class[] { java.io.ObjectOutputStream.class });
        }
        catch (SecurityException e)
        {
          // we can't access/ set accessible to true
          writeObjectMethodCache.put(cls, Boolean.FALSE);
        }
        catch (NoSuchMethodException e)
        {
          // cls doesn't have that method
          writeObjectMethodCache.put(cls, Boolean.FALSE);
        }
      }

      final Object original = obj;
      if (writeObjectMethod != null)
      {
        class InterceptingObjectOutputStream extends ObjectOutputStream
        {
          private int counter;

          InterceptingObjectOutputStream() throws IOException
          {
            super(DUMMY_OUTPUT_STREAM);
            enableReplaceObject(true);
          }

          protected Object replaceObject(Object streamObj) throws IOException
          {
            if (streamObj == original)
            {
              return streamObj;
            }

            counter++;
            // Check for circular reference.
            if (checked.containsKey(streamObj))
            {
              return null;
            }

            checked.put(original, null);
            String arrayPos = "[write:" + counter + "]";
            simpleName = arrayPos;
            fieldDescription += arrayPos;
            check(streamObj);
            return streamObj;
          }
        }
        try
        {
          InterceptingObjectOutputStream ioos = new InterceptingObjectOutputStream();
          ioos.writeObject(obj);
        }
        catch (Exception e)
        {
          if (e instanceof WicketNotSerializableException)
          {
            throw (WicketNotSerializableException)e;
          }
          log.warn("error delegating to writeObject : " + e.getMessage() + ", path: " +
              currentPath());
        }
      }
      else
      {
        Object[] slots;
        try
        {
          slots = (Object[])GET_CLASS_DATA_LAYOUT_METHOD.invoke(desc, null);
        }
        catch (Exception e)
        {
          throw new RuntimeException(e);
        }
        for (int i = 0; i < slots.length; i++)
        {
          ObjectStreamClass slotDesc;
          try
          {
            Field descField = slots[i].getClass().getDeclaredField("desc");
            descField.setAccessible(true);
            slotDesc = (ObjectStreamClass)descField.get(slots[i]);
View Full Code Here

        protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
            boolean ser = readBoolean();
            if (ser) {
                String clsName = readUTF();
                ObjectStreamClass cached = _classDescriptors.get(clsName);
                if (cached == null) {
                    cached = ObjectStreamClass.lookup(Class.forName(clsName, true, _classLoader));
                    _classDescriptors.put(clsName, cached);
                }
                return cached;
View Full Code Here

        protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
            boolean ser = readBoolean();
            if (ser) {
                String clsName = readUTF();
                ObjectStreamClass cached = _classDescriptors.get(clsName);
                if (cached == null) {
                    cached = ObjectStreamClass.lookup(Class.forName(clsName, true, _classLoader));
                    _classDescriptors.put(clsName, cached);
                }
                return cached;
View Full Code Here

            }
        }
        // Stores the serial version uid for serializable classes
        if (moClass.isSerializable) {
            try {
                ObjectStreamClass oserial = ObjectStreamClass.lookup(
                        Class.forName(name.replace('/', '.')));
            } catch (Exception e) {
                logger.log(BasicLevel.WARN,
                        "Impossible to find the VersionUID of the class", e);
            }
View Full Code Here

    /**
     * @tests serilization
     */
    public void test_objectStreamClass_getFields() throws Exception {
        // Regression for HARMONY-2674
        ObjectStreamClass objectStreamClass = ObjectStreamClass
                .lookup(File.class);
        ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
        assertEquals(1, objectStreamFields.length);
        ObjectStreamField objectStreamField = objectStreamFields[0];
        assertEquals("path", objectStreamField.getName());
        assertEquals(String.class, objectStreamField.getType());
    }
View Full Code Here

    {
      throw new WicketNotSerializableException(toPrettyPrintedStack(obj.getClass().getName())
          .toString(), exception);
    }

    ObjectStreamClass desc;
    for (;;)
    {
      try
      {
        desc = (ObjectStreamClass)LOOKUP_METHOD.invoke(null, new Object[] { cls,
            Boolean.TRUE });
        Class repCl;
        if (!((Boolean)HAS_WRITE_REPLACE_METHOD_METHOD.invoke(desc, null)).booleanValue()
            || (obj = INVOKE_WRITE_REPLACE_METHOD.invoke(desc, new Object[] { obj })) == null
            || (repCl = obj.getClass()) == cls)
        {
          break;
        }
        cls = repCl;
      }
      catch (IllegalAccessException e)
      {
        throw new RuntimeException(e);
      }
      catch (InvocationTargetException e)
      {
        throw new RuntimeException(e);
      }
    }

    if (cls.isPrimitive())
    {
      // skip
    }
    else if (cls.isArray())
    {
      checked.put(obj, null);
      Class ccl = cls.getComponentType();
      if (!(ccl.isPrimitive()))
      {
        Object[] objs = (Object[])obj;
        for (int i = 0; i < objs.length; i++)
        {
          String arrayPos = "[" + i + "]";
          simpleName = arrayPos;
          fieldDescription += arrayPos;
          check(objs[i]);
        }
      }
    }
    else if (obj instanceof Externalizable && (!Proxy.isProxyClass(cls)))
    {
      Externalizable extObj = (Externalizable)obj;
      try
      {
        extObj.writeExternal(new ObjectOutputAdaptor()
        {
          private int count = 0;

          public void writeObject(Object streamObj) throws IOException
          {
            // Check for circular reference.
            if (checked.containsKey(streamObj))
            {
              return;
            }

            checked.put(streamObj, null);
            String arrayPos = "[write:" + count++ + "]";
            simpleName = arrayPos;
            fieldDescription += arrayPos;

            check(streamObj);
          }
        });
      }
      catch (Exception e)
      {
        if (e instanceof WicketNotSerializableException)
        {
          throw (WicketNotSerializableException)e;
        }
        log.warn("error delegating to Externalizable : " + e.getMessage() + ", path: "
            + currentPath());
      }
    }
    else
    {
      Method writeObjectMethod = null;
      Object o = writeObjectMethodCache.get(cls);
      if (o != null)
      {
        if (o instanceof Method)
        {
          writeObjectMethod = (Method)o;
        }
      }
      else
      {
        try
        {
          writeObjectMethod = cls.getDeclaredMethod("writeObject",
              new Class[] { java.io.ObjectOutputStream.class });
        }
        catch (SecurityException e)
        {
          // we can't access/ set accessible to true
          writeObjectMethodCache.put(cls, Boolean.FALSE);
        }
        catch (NoSuchMethodException e)
        {
          // cls doesn't have that method
          writeObjectMethodCache.put(cls, Boolean.FALSE);
        }
      }

      final Object original = obj;
      if (writeObjectMethod != null)
      {
        class InterceptingObjectOutputStream extends ObjectOutputStream
        {
          private int counter;

          InterceptingObjectOutputStream() throws IOException
          {
            super(DUMMY_OUTPUT_STREAM);
            enableReplaceObject(true);
          }

          protected Object replaceObject(Object streamObj) throws IOException
          {
            if (streamObj == original)
            {
              return streamObj;
            }

            counter++;
            // Check for circular reference.
            if (checked.containsKey(streamObj))
            {
              return null;
            }

            checked.put(original, null);
            String arrayPos = "[write:" + counter + "]";
            simpleName = arrayPos;
            fieldDescription += arrayPos;
            check(streamObj);
            return streamObj;
          }
        }
        try
        {
          InterceptingObjectOutputStream ioos = new InterceptingObjectOutputStream();
          ioos.writeObject(obj);
        }
        catch (Exception e)
        {
          if (e instanceof WicketNotSerializableException)
          {
            throw (WicketNotSerializableException)e;
          }
          log.warn("error delegating to writeObject : " + e.getMessage() + ", path: "
              + currentPath());
        }
      }
      else
      {
        Object[] slots;
        try
        {
          slots = (Object[])GET_CLASS_DATA_LAYOUT_METHOD.invoke(desc, null);
        }
        catch (Exception e)
        {
          throw new RuntimeException(e);
        }
        for (int i = 0; i < slots.length; i++)
        {
          ObjectStreamClass slotDesc;
          try
          {
            Field descField = slots[i].getClass().getDeclaredField("desc");
            descField.setAccessible(true);
            slotDesc = (ObjectStreamClass)descField.get(slots[i]);
View Full Code Here

  @Override
  protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException
  {
    String name = readUTF();
    ObjectStreamClass lookup = ObjectStreamClass.lookup(Class.forName(name));
    return lookup;
  }
View Full Code Here

            else
                b.append("\\U").append(toHexString((int)c));
        }
        long clsHash = getClassHashCode(cls);
        b.append(':').append(toHexString(clsHash));
        ObjectStreamClass osClass = ObjectStreamClass.lookup(cls);
        if (osClass != null) {
            long serialVersionUID = osClass.getSerialVersionUID();
            if (clsHash != serialVersionUID)
                b.append(':').append(toHexString(serialVersionUID));
        }
        result = b.toString();
        classIRIdentifierCache.put(cls, result);
View Full Code Here

            StringBuffer b = new StringBuffer("RMI:");
            b.append(escapeIRName(javaClass.getName()));
            memberPrefix = b.toString() + ".";
            String hashStr = toHexString(classHashCode);
            b.append(':').append(hashStr);
            ObjectStreamClass osClass = ObjectStreamClass.lookup(javaClass);
            if (osClass != null) {
                long serialVersionUID = osClass.getSerialVersionUID();
                String SVUID = toHexString(serialVersionUID);
                if (classHashCode != serialVersionUID)
                    b.append(':').append(SVUID);
                memberPostfix = ":" + hashStr + ":" + SVUID;
            } else
View Full Code Here

TOP

Related Classes of java.io.ObjectStreamClass$OSCThreadLocalCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.