Search in sources :

Example 56 with ObjectStreamClass

use of java.io.ObjectStreamClass in project j2objc by google.

the class MyObjectInputStream method test_getType_MockObjectInputStream.

/**
 * java.io.ObjectStreamField#getType()
 */
public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(new SerializableObject());
    oos.close();
    baos.close();
    byte[] bytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    MockObjectInputStream ois = new MockObjectInputStream(bais);
    ois.readObject();
    ObjectStreamClass oc = ois.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectStreamField(java.io.ObjectStreamField) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass)

Example 57 with ObjectStreamClass

use of java.io.ObjectStreamClass in project j2objc by google.

the class MyObjectInputStream method test_isUnshared.

public void test_isUnshared() throws Exception {
    SerializableObject2 obj = new SerializableObject2();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    oos.close();
    baos.close();
    byte[] bytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject2 newObj = (SerializableObject2) ois.readObject();
    ObjectInputStream.GetField getField = newObj.getGetField();
    ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
    assertTrue(objectStreamClass.getField("i").isUnshared());
    assertFalse(objectStreamClass.getField("d").isUnshared());
    assertTrue(objectStreamClass.getField("s").isUnshared());
    assertEquals(1000, getField.get("i", null));
    assertEquals(SerializableObject2.today, getField.get("d", null));
    assertEquals("Richard", getField.get("s", null));
    assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
    assertEquals(0, objectStreamClass.getField("d").getOffset());
    assertEquals(1, objectStreamClass.getField("i").getOffset());
    assertEquals(2, objectStreamClass.getField("s").getOffset());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Example 58 with ObjectStreamClass

use of java.io.ObjectStreamClass in project j2objc by google.

the class ObjectStreamClassTest method test_getFieldLjava_lang_String.

/**
 * 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"));
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass)

Example 59 with ObjectStreamClass

use of java.io.ObjectStreamClass in project j2objc by google.

the class ObjectStreamClassTest method test_forClass.

/**
 * 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);
    assertEquals("forClass returned an object: " + osc.forClass(), DummyClass.class, osc.forClass());
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass)

Example 60 with ObjectStreamClass

use of java.io.ObjectStreamClass in project j2objc by google.

the class ObjectStreamClassTest method test_getFields.

/**
 * java.io.ObjectStreamClass#getFields()
 */
public void test_getFields() {
    ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
    ObjectStreamField[] osfArray = osc.getFields();
    assertTrue("Array of fields should be of length 2 but is instead of length: " + osfArray.length, osfArray.length == 2);
}
Also used : ObjectStreamField(java.io.ObjectStreamField) ObjectStreamClass(java.io.ObjectStreamClass)

Aggregations

ObjectStreamClass (java.io.ObjectStreamClass)70 IOException (java.io.IOException)27 ObjectInputStream (java.io.ObjectInputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ObjectOutputStream (java.io.ObjectOutputStream)14 ObjectStreamField (java.io.ObjectStreamField)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Serializable (java.io.Serializable)7 InvalidClassException (java.io.InvalidClassException)3 Field (java.lang.reflect.Field)3 ORecordBytes (com.orientechnologies.orient.core.record.impl.ORecordBytes)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JavaCompiler (javax.tools.JavaCompiler)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 Test (org.junit.Test)2 ParseException (org.locationtech.jts.io.ParseException)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)1 OGroup (eu.esdihumboldt.hale.common.instance.orient.OGroup)1