Package java.io

Examples of java.io.ObjectStreamClass$OSCThreadLocalCache


        assertNotNull(three.getStringField());
        map.put("three", three);
        three = (TestSerial) map.get("three");
        assertEquals(two, three.getOther());

        ObjectStreamClass desc = ObjectStreamClass.lookup(TestSerial.class);

        assertNotNull(catalog.getClassID(desc));
        assertNotNull(catalog.getClassID(desc));

        // test with empty catalog
View Full Code Here


        throws DatabaseException, ClassNotFoundException {

        /* First check the map and, if found, add class info to the map. */

        BigInteger classIDObj = new BigInteger(classID);
        ObjectStreamClass classFormat =
            (ObjectStreamClass) formatMap.get(classIDObj);
        if (classFormat == null) {

            /* Make the class format key. */

 
View Full Code Here

                 * Read class info to get the class format key, then read class
                 * format.
                 */
                classInfo = new ClassInfo(data);
                DatabaseEntry formatData = new DatabaseEntry();
                ObjectStreamClass storedClassFormat =
                    getClassFormat(classInfo.getClassID(), formatData);

                /*
                 * Compare the stored class format to the current class format,
                 * and if they are different then generate a new class ID.
View Full Code Here

                    writer.endNode();
                }
            }

            public void writeFieldsToStream(Map fields) {
                ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);

                writer.startNode(ELEMENT_DEFAULT);
                for (Iterator iterator = fields.keySet().iterator(); iterator.hasNext();) {
                    String name = (String) iterator.next();
                    if (!mapper.shouldSerializeMember(currentType[0], name)) {
                        continue;
                    }
                    ObjectStreamField field = objectStreamClass.getField(name);
                    Object value = fields.get(name);
                    if (field == null) {
                        throw new ObjectAccessException("Class " + value.getClass().getName()
                                + " may not write a field named '" + name + "'");
                    }
                    if (value != null) {
                        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source.getClass(), name), field.getType());
                        if (field.getType() != value.getClass() && !field.getType().isPrimitive()) {
                            String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
                            if (attributeName != null) {
                                writer.addAttribute(attributeName, mapper.serializedClass(value.getClass()));
                            }
                        }
                        context.convertAnother(value);
                        writer.endNode();
                    }
                }
                writer.endNode();
            }

            public void defaultWriteObject() {
                boolean writtenDefaultFields = false;

                ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);

                if (objectStreamClass == null) {
                    return;
                }

                ObjectStreamField[] fields = objectStreamClass.getFields();
                for (int i = 0; i < fields.length; i++) {
                    ObjectStreamField field = fields[i];
                    Object value = readField(field, currentType[0], source);
                    if (value != null) {
                        if (!writtenClassWrapper[0]) {
View Full Code Here

                        fields.put(name, value);
                        reader.moveUp();
                    }
                } else if (reader.getNodeName().equals(ELEMENT_DEFAULT)) {
                    // New format introduced in XStream 1.1.1
                    ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
                    while (reader.hasMoreChildren()) {
                        reader.moveDown();
                        String name = mapper.realMember(currentType[0], reader.getNodeName());
                        if (mapper.shouldSerializeMember(currentType[0], name)) {
                String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
                            Class type;
                            if (classAttribute != null) {
                                type = mapper.realClass(classAttribute);
                            } else {
                                ObjectStreamField field = objectStreamClass.getField(name);
                                if (field == null) {
                                    throw new ObjectAccessException("Class " + currentType[0]
                                            + " does not contain a field named '" + name + "'");
                                }
                                type = field.getType();
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, (Object[])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 });
          writeObjectMethodCache.put(cls, writeObjectMethod);
        }
        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);
          }

          @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(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, (Object[])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

    public synchronized ObjectStreamClass getClassFormat(byte[] id)
        throws DatabaseException {

        String strId = new String(id);
        ObjectStreamClass desc = (ObjectStreamClass) idToDescMap.get(strId);
        if (desc == null) {
            throw new DatabaseException("classID not found");
        }
        return desc;
    }
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

     * @tests java.io.ObjectStreamClass#forClass()
     */
    public void test_forClass() {
        // Need to test during serialization to be sure an instance is
        // returned
        ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
        assertTrue("forClass returned an object: " + osc.forClass(), osc
                .forClass().equals(DummyClass.class));
    }
View Full Code Here

    /**
     * @tests java.io.ObjectStreamClass#getField(java.lang.String)
     */
    public void test_getFieldLjava_lang_String() {
        ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
        assertEquals("getField did not return correct field", 'J', osc
                .getField("bam").getTypeCode());
        assertNull("getField did not null for non-existent field", osc
                .getField("wham"));
    }
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.