Package java.io

Examples of java.io.ObjectStreamClass


                .getOptions());
    } else {
      m_ClassifierOptions = "";
    }
    if (m_Template instanceof Serializable) {
      ObjectStreamClass obs = ObjectStreamClass.lookup(m_Template
                   .getClass());
      m_ClassifierVersion = "" + obs.getSerialVersionUID();
    } else {
      m_ClassifierVersion = "";
    }
  }
View Full Code Here


                .getOptions());
    } else {
      m_ClassifierOptions = "";
    }
    if (m_Template instanceof Serializable) {
      ObjectStreamClass obs = ObjectStreamClass.lookup(m_Template
                   .getClass());
      m_ClassifierVersion = "" + obs.getSerialVersionUID();
    } else {
      m_ClassifierVersion = "";
    }
  }
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

 
 
  public void testFormats() throws Exception
  {
   
    ObjectStreamClass o = ObjectStreamClass.lookup(Format.class);
//    System.out.println(o.getSerialVersionUID());

    assertEquals(o.getSerialVersionUID(), 5612854984030969319L);
   
    //System.out.println(computeDefaultSUID(WavAudioFormat.class));
   
    assertEquals(computeDefaultSUID(VideoFormat.class), 8024602108723869163L);
    assertEquals(ObjectStreamClass.lookup(javax.media.format.VideoFormat.class).getSerialVersionUID(), 3595293544666171102L);
View Full Code Here

      CodeSource cs = c.getProtectionDomain().getCodeSource();
      if( cs != null )
         location = cs.getLocation();
      if( c.isInterface() == false )
      {
         ObjectStreamClass osc = ObjectStreamClass.lookup(c);
         if( osc != null )
         {
            serialVersion = osc.getSerialVersionUID();
            try
            {
               c.getDeclaredField("serialVersionUID");
               hasExplicitSerialVersionUID = true;
            }
View Full Code Here

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

    ObjectStreamClass desc;
    for (;;)
    {
      try
      {
        desc = (ObjectStreamClass)LOOKUP_METHOD.invoke(null, cls, Boolean.TRUE);
        Class<?> repCl;
        if (!(Boolean)HAS_WRITE_REPLACE_METHOD_METHOD.invoke(desc, (Object[])null) ||
          (obj = INVOKE_WRITE_REPLACE_METHOD.invoke(desc, 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;

          @Override
          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;
      if (writeObjectMethodMissing.contains(cls) == false)
      {
        try
        {
          writeObjectMethod = cls.getDeclaredMethod("writeObject",
            new Class[] { java.io.ObjectOutputStream.class });
        }
        catch (SecurityException e)
        {
          // we can't access / set accessible to true
          writeObjectMethodMissing.add(cls);
        }
        catch (NoSuchMethodException e)
        {
          // cls doesn't have that method
          writeObjectMethodMissing.add(cls);
        }
      }

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

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

          @Override
          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(streamObj, 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, (Object[])null);
        }
        catch (Exception e)
        {
          throw new RuntimeException(e);
        }
        for (Object slot : slots)
        {
          ObjectStreamClass slotDesc;
          try
          {
            Field descField = slot.getClass().getDeclaredField("desc");
            descField.setAccessible(true);
            slotDesc = (ObjectStreamClass)descField.get(slot);
View Full Code Here

    }

    static long computeStructuralUID(ValueType vt)
    {
        Class c = vt._class;
        ObjectStreamClass osc = vt._objectStreamClass;
        ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);
        long h = 0;
        try
        {
            if (! java.io.Serializable.class.isAssignableFrom(c)
View Full Code Here

            lookupClass = Class.forName(className, true, classLoader);
        } else {
            lookupClass = Class.forName(idToDesc.get(id), true, classLoader);
        }
       
        ObjectStreamClass ret = ObjectStreamClass.lookup(lookupClass);
        if (ret == null) {
            throw new IOException("Unknown class ID " + id);
        }
       
        return ret;
View Full Code Here

        String exceptionMessage = result.reason + '\n' + prettyPrintMessage;
        throw new ObjectCheckException(exceptionMessage, result.cause);
      }
    }

    ObjectStreamClass desc;
    for (;;)
    {
      try
      {
        desc = (ObjectStreamClass)LOOKUP_METHOD.invoke(null, cls, Boolean.TRUE);
        Class<?> repCl;
        if (!(Boolean)HAS_WRITE_REPLACE_METHOD_METHOD.invoke(desc, (Object[])null) ||
            (obj = INVOKE_WRITE_REPLACE_METHOD.invoke(desc, obj)) == null ||
            (repCl = obj.getClass()) == cls)
        {
          break;
        }
        cls = repCl;
      }
      catch (IllegalAccessException | 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++)
        {
          CharSequence arrayPos = new StringBuilder(4).append('[').append(i).append(']');
          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;

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

            checked.put(streamObj, null);
            CharSequence arrayPos = new StringBuilder(10).append("[write:").append(count++).append(']');
            simpleName = arrayPos;
            fieldDescription += arrayPos;

            check(streamObj);
          }
        });
      }
      catch (Exception e)
      {
        if (e instanceof ObjectCheckException)
        {
          throw (ObjectCheckException)e;
        }
        log.warn("Error delegating to Externalizable : {}, path: {}", e.getMessage(), currentPath());
      }
    }
    else
    {
      Method writeObjectMethod = null;
      if (writeObjectMethodMissing.contains(cls) == false)
      {
        try
        {
          writeObjectMethod = cls.getDeclaredMethod("writeObject",
              new Class[] { java.io.ObjectOutputStream.class });
        }
        catch (SecurityException e)
        {
          // we can't access / set accessible to true
          writeObjectMethodMissing.add(cls);
        }
        catch (NoSuchMethodException e)
        {
          // cls doesn't have that method
          writeObjectMethodMissing.add(cls);
        }
      }

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

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

          @Override
          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(streamObj, null);
            CharSequence arrayPos = new StringBuilder(10).append("[write:").append(counter).append(']');
            simpleName = arrayPos;
            fieldDescription += arrayPos;
            check(streamObj);
            return streamObj;
          }
        }
        try
        {
          InterceptingObjectOutputStream ioos = new InterceptingObjectOutputStream();
          ioos.writeObject(obj);
        }
        catch (Exception e)
        {
          if (e instanceof ObjectCheckException)
          {
            throw (ObjectCheckException)e;
          }
          log.warn("error delegating to writeObject : {}, path: {}", e.getMessage(), currentPath());
        }
      }
      else
      {
        Object[] slots;
        try
        {
          slots = (Object[])GET_CLASS_DATA_LAYOUT_METHOD.invoke(desc, (Object[])null);
        }
        catch (Exception e)
        {
          throw new RuntimeException(e);
        }
        for (Object slot : slots)
        {
          ObjectStreamClass slotDesc;
          try
          {
            Field descField = slot.getClass().getDeclaredField("desc");
            descField.setAccessible(true);
            slotDesc = (ObjectStreamClass)descField.get(slot);
View Full Code Here

        String exceptionMessage = result.reason + '\n' + prettyPrintMessage;
        throw new ObjectCheckException(exceptionMessage, result.cause);
      }
    }

    ObjectStreamClass desc;
    for (;;)
    {
      try
      {
        desc = (ObjectStreamClass)LOOKUP_METHOD.invoke(null, cls, Boolean.TRUE);
        Class<?> repCl;
        if (!(Boolean)HAS_WRITE_REPLACE_METHOD_METHOD.invoke(desc, (Object[])null) ||
            (obj = INVOKE_WRITE_REPLACE_METHOD.invoke(desc, 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++)
        {
          CharSequence arrayPos = new StringBuilder(4).append('[').append(i).append(']');
          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;

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

            checked.put(streamObj, null);
            CharSequence arrayPos = new StringBuilder(10).append("[write:").append(count++).append(']');
            simpleName = arrayPos;
            fieldDescription += arrayPos;

            check(streamObj);
          }
        });
      }
      catch (Exception e)
      {
        if (e instanceof ObjectCheckException)
        {
          throw (ObjectCheckException)e;
        }
        log.warn("Error delegating to Externalizable : {}, path: {}", e.getMessage(), currentPath());
      }
    }
    else
    {
      Method writeObjectMethod = null;
      if (writeObjectMethodMissing.contains(cls) == false)
      {
        try
        {
          writeObjectMethod = cls.getDeclaredMethod("writeObject",
              new Class[] { java.io.ObjectOutputStream.class });
        }
        catch (SecurityException e)
        {
          // we can't access / set accessible to true
          writeObjectMethodMissing.add(cls);
        }
        catch (NoSuchMethodException e)
        {
          // cls doesn't have that method
          writeObjectMethodMissing.add(cls);
        }
      }

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

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

          @Override
          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(streamObj, null);
            CharSequence arrayPos = new StringBuilder(10).append("[write:").append(counter).append(']');
            simpleName = arrayPos;
            fieldDescription += arrayPos;
            check(streamObj);
            return streamObj;
          }
        }
        try
        {
          InterceptingObjectOutputStream ioos = new InterceptingObjectOutputStream();
          ioos.writeObject(obj);
        }
        catch (Exception e)
        {
          if (e instanceof ObjectCheckException)
          {
            throw (ObjectCheckException)e;
          }
          log.warn("error delegating to writeObject : {}, path: {}", e.getMessage(), currentPath());
        }
      }
      else
      {
        Object[] slots;
        try
        {
          slots = (Object[])GET_CLASS_DATA_LAYOUT_METHOD.invoke(desc, (Object[])null);
        }
        catch (Exception e)
        {
          throw new RuntimeException(e);
        }
        for (Object slot : slots)
        {
          ObjectStreamClass slotDesc;
          try
          {
            Field descField = slot.getClass().getDeclaredField("desc");
            descField.setAccessible(true);
            slotDesc = (ObjectStreamClass)descField.get(slot);
View Full Code Here

TOP

Related Classes of java.io.ObjectStreamClass

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.