Java 类java.io.ObjectStreamField 实例源码

项目:OpenJSharp    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:openjdk-jdk10    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:openjdk9    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:lookaside_java-1.8.0-openjdk    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:jdk8u_corba    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:j2objc    文件:ObjectStreamClassTest.java   
public void test_specialTypes() {
    Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
            .getClassLoader(), new Class[] { Runnable.class });

    ObjectStreamClass proxyStreamClass = ObjectStreamClass
            .lookup(proxyClass);

    assertEquals("Proxy classes should have zero serialVersionUID", 0,
            proxyStreamClass.getSerialVersionUID());
    ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
    assertEquals("Proxy classes should have no serialized fields", 0,
            proxyFields.length);

    ObjectStreamClass enumStreamClass = ObjectStreamClass
            .lookup(Thread.State.class);

    assertEquals("Enum classes should have zero serialVersionUID", 0,
            enumStreamClass.getSerialVersionUID());
    ObjectStreamField[] enumFields = enumStreamClass.getFields();
    assertEquals("Enum classes should have no serialized fields", 0,
            enumFields.length);
}
项目:j2objc    文件:ObjectStreamFieldTest.java   
/**
 * java.io.ObjectStreamField#getType()
 */
public void test_getType_Deserialized() 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);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject obj = (SerializableObject) ois.readObject();

    ObjectStreamClass oc = obj.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
项目:j2objc    文件:ObjectStreamFieldTest.java   
/**
 * 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());
}
项目:infobip-open-jdk-8    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:In-the-Box-Fork    文件:ObjectStreamClassTest.java   
public void test_specialTypes() {
    Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
            .getClassLoader(), new Class[] { Runnable.class });

    ObjectStreamClass proxyStreamClass = ObjectStreamClass
            .lookup(proxyClass);

    assertEquals("Proxy classes should have zero serialVersionUID", 0,
            proxyStreamClass.getSerialVersionUID());
    ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
    assertEquals("Proxy classes should have no serialized fields", 0,
            proxyFields.length);

    ObjectStreamClass enumStreamClass = ObjectStreamClass
            .lookup(Thread.State.class);

    assertEquals("Enum classes should have zero serialVersionUID", 0,
            enumStreamClass.getSerialVersionUID());
    ObjectStreamField[] enumFields = enumStreamClass.getFields();
    assertEquals("Enum classes should have no serialized fields", 0,
            enumFields.length);
}
项目:In-the-Box-Fork    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getOffset()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getOffset",
    args = {}
)
public void test_getOffset() {
    // Test for method int java.io.ObjectStreamField.getOffset()
    ObjectStreamField[] osfArray;
    osfArray = osc.getFields();
    int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};

    assertTrue("getOffset() did not return reasonable values.", osfArray[0]
            .getOffset() != osfArray[1].getOffset());

    for (int i = 0; i < expectedOffsets.length; i++) {
        assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
                expectedOffsets[i], osfArray[i].getOffset());

    }
}
项目:In-the-Box-Fork    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getType()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getType",
    args = {}
)
public void test_getType_Deserialized() 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);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject obj = (SerializableObject) ois.readObject();

    ObjectStreamClass oc = obj.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
项目:In-the-Box-Fork    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getType()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getType",
    args = {}
)
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());
}
项目:In-the-Box-Fork    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#isPrimitive()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "isPrimitive",
    args = {}
)
public void test_isPrimitive() {
    // Test for method int java.io.ObjectStreamField.getOffset()
    ObjectStreamField[] osfArray;
    osfArray = osc.getFields();

    for (int i = 0; i < (osfArray.length - 1); i++) {
        assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
                   osfArray[i].isPrimitive());
    }
    assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
                              osfArray.length - 1),
                osfArray[(osfArray.length - 1)].isPrimitive());
}
项目:In-the-Box-Fork    文件:FileTest.java   
/**
 * @tests serialization
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "regression test",
    method = "!Serialization",
    args = {}
)
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());
}
项目:DataCleaner    文件:AbstractLegacyAwareInputRow.java   
/**
 * Subclasses should call this method within their
 * readObject(ObjectInputStream) invocations
 *
 * @param stream
 * @throws IOException
 * @throws ClassNotFoundException
 */
protected void doReadObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
    final GetField readFields = stream.readFields();

    for (final String fieldName : getFieldNamesInAdditionToId()) {
        final Object value = readFields.get(fieldName, null);
        setField(fieldName, value);
    }

    // fix issue of deserializing _rowNumber in it's previous int form
    final long rowNumber;
    final ObjectStreamField legacyRowNumberField =
            readFields.getObjectStreamClass().getField(getFieldNameForOldId());
    if (legacyRowNumberField != null) {
        rowNumber = readFields.get(getFieldNameForOldId(), -1);
    } else {
        rowNumber = readFields.get(getFieldNameForNewId(), -1L);
    }

    setField(getFieldNameForNewId(), rowNumber);
}
项目:openjdk-source-code-learn    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:OLD-OpenJDK8    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:cn1    文件:ObjectStreamClassTest.java   
public void test_specialTypes() {
    Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
            .getClassLoader(), new Class[] { Runnable.class });

    ObjectStreamClass proxyStreamClass = ObjectStreamClass
            .lookup(proxyClass);

    assertEquals("Proxy classes should have zero serialVersionUID", 0,
            proxyStreamClass.getSerialVersionUID());
    ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
    assertEquals("Proxy classes should have no serialized fields", 0,
            proxyFields.length);

    ObjectStreamClass enumStreamClass = ObjectStreamClass
            .lookup(Thread.State.class);

    assertEquals("Enum classes should have zero serialVersionUID", 0,
            enumStreamClass.getSerialVersionUID());
    ObjectStreamField[] enumFields = enumStreamClass.getFields();
    assertEquals("Enum classes should have no serialized fields", 0,
            enumFields.length);
}
项目:cn1    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getType()
 */
public void test_getType_Deserialized() 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);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject obj = (SerializableObject) ois.readObject();

    ObjectStreamClass oc = obj.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
项目:cn1    文件:ObjectStreamFieldTest.java   
/**
 * @tests 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());
}
项目:freeVM    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getType() 
 */
public void test_getType_Deserialized() 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);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject obj = (SerializableObject) ois.readObject();

    ObjectStreamClass oc = obj.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
项目:freeVM    文件:ObjectStreamFieldTest.java   
/**
 * @tests 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());
}
项目:freeVM    文件:ObjectStreamClassTest.java   
public void test_specialTypes() {
    Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
            .getClassLoader(), new Class[] { Runnable.class });

    ObjectStreamClass proxyStreamClass = ObjectStreamClass
            .lookup(proxyClass);

    assertEquals("Proxy classes should have zero serialVersionUID", 0,
            proxyStreamClass.getSerialVersionUID());
    ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
    assertEquals("Proxy classes should have no serialized fields", 0,
            proxyFields.length);

    ObjectStreamClass enumStreamClass = ObjectStreamClass
            .lookup(Thread.State.class);

    assertEquals("Enum classes should have zero serialVersionUID", 0,
            enumStreamClass.getSerialVersionUID());
    ObjectStreamField[] enumFields = enumStreamClass.getFields();
    assertEquals("Enum classes should have no serialized fields", 0,
            enumFields.length);
}
项目:freeVM    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getType()
 */
public void test_getType_Deserialized() 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);
    ObjectInputStream ois = new ObjectInputStream(bais);
    SerializableObject obj = (SerializableObject) ois.readObject();

    ObjectStreamClass oc = obj.getObjectStreamClass();
    ObjectStreamField field = oc.getField("i");
    assertEquals(Object.class, field.getType());
}
项目:freeVM    文件:ObjectStreamFieldTest.java   
/**
 * @tests 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());
}
项目:openjdk-icedtea7    文件:ValueType.java   
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
项目:j2objc    文件:ObjectStreamClassTest.java   
/**
 * 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);
}
项目:j2objc    文件:ObjectStreamFieldTest.java   
/**
 * java.io.ObjectStreamField#getOffset()
 */
public void test_getOffset() {
    ObjectStreamField[] osfArray;
    osfArray = osc.getFields();
    assertTrue("getOffset did not return reasonable values", osfArray[0]
            .getOffset() != osfArray[1].getOffset());
    assertEquals("getOffset for osfArray[0].getOffset() did not return 0",
            0, osfArray[0].getOffset());
    assertEquals("osfArray[1].getOffset() did not return    8", 8, osfArray[1]
            .getOffset());
    assertEquals("osfArray[2].getOffset() did not return 12", 12,
            osfArray[2].getOffset());
}
项目:j2objc    文件:ObjectStreamFieldTest.java   
/**
 * java.io.ObjectStreamField#getTypeString()
 */
public void test_getTypeString() {
    assertTrue("getTypeString returned: " + holaField.getTypeString(),
            holaField.getTypeString().indexOf("Object") >= 0);
    assertNull("Primitive types' strings should be null", hamField
            .getTypeString());

    ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
    assertTrue(osf.getTypeString() == "Ljava/lang/String;");
}
项目:j2objc    文件:SerializationTest.java   
public void testSerializeFieldMadeTransient() throws Exception {
    // Does ObjectStreamClass have the right idea?
    ObjectStreamClass osc = ObjectStreamClass.lookup(FieldMadeTransient.class);
    ObjectStreamField[] fields = osc.getFields();
    assertEquals(1, fields.length);
    assertEquals("nonTransientInt", fields[0].getName());
    assertEquals(int.class, fields[0].getType());

    // this was created by serializing a FieldMadeTransient with a non-0 transientInt
    String s = "aced0005737200346c6962636f72652e6a6176612e696f2e53657269616c697a6174696f6e54657"
            + "374244669656c644d6164655472616e7369656e74000000000000000002000149000c7472616e736"
            + "9656e74496e747870abababab";
    FieldMadeTransient deserialized = (FieldMadeTransient) SerializationTester.deserializeHex(s);
    assertEquals(0, deserialized.transientInt);
}
项目:j2objc    文件:OldObjectStreamFieldTest.java   
public void test_getOffset() {
    ObjectStreamField[] osfArray;
    osfArray = osc.getFields();
    int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};

    assertTrue("getOffset() did not return reasonable values.", osfArray[0]
            .getOffset() != osfArray[1].getOffset());

    for (int i = 0; i < expectedOffsets.length; i++) {
        assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
                expectedOffsets[i], osfArray[i].getOffset());

    }
}
项目:j2objc    文件:OldObjectStreamFieldTest.java   
public void test_isPrimitive() {
    // Test for method int java.io.ObjectStreamField.getOffset()
    ObjectStreamField[] osfArray;
    osfArray = osc.getFields();

    for (int i = 0; i < (osfArray.length - 1); i++) {
        assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
                   osfArray[i].isPrimitive());
    }
    assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
                              osfArray.length - 1),
                osfArray[(osfArray.length - 1)].isPrimitive());
}
项目:In-the-Box-Fork    文件:FileTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:ObjectStreamClassTest.java   
/**
 * @tests 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);
}
项目:In-the-Box-Fork    文件:ObjectStreamFieldTest.java   
/**
 * @tests java.io.ObjectStreamField#getTypeString()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getTypeString",
    args = {}
)
public void test_getTypeString() {
    assertTrue("getTypeString returned: " + holaField.getTypeString(),
            holaField.getTypeString().indexOf("Object") >= 0);
    assertNull("Primitive types' strings should be null", hamField.getTypeString());

    ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
    assertTrue(osf.getTypeString() == "Ljava/lang/String;");
}
项目:QuizUpWinner    文件:SerializableConverter.java   
private Object readField(ObjectStreamField paramObjectStreamField, Class paramClass, Object paramObject)
{
  try
  {
    Field localField = paramClass.getDeclaredField(paramObjectStreamField.getName());
    if (!localField.isAccessible())
      localField.setAccessible(true);
    Object localObject = localField.get(paramObject);
    return localObject;
  }
  catch (IllegalArgumentException localIllegalArgumentException)
  {
    throw new ObjectAccessException("Could not get field " + paramObjectStreamField.getClass() + "." + paramObjectStreamField.getName(), localIllegalArgumentException);
  }
  catch (IllegalAccessException localIllegalAccessException)
  {
    throw new ObjectAccessException("Could not get field " + paramObjectStreamField.getClass() + "." + paramObjectStreamField.getName(), localIllegalAccessException);
  }
  catch (NoSuchFieldException localNoSuchFieldException)
  {
    throw new ObjectAccessException("Could not get field " + paramObjectStreamField.getClass() + "." + paramObjectStreamField.getName(), localNoSuchFieldException);
  }
  catch (SecurityException localSecurityException)
  {
    throw new ObjectAccessException("Could not get field " + paramObjectStreamField.getClass() + "." + paramObjectStreamField.getName(), localSecurityException);
  }
}
项目:DataCleaner    文件:ChangeAwareObjectInputStream.java   
private String[] getFieldNames(final ObjectStreamClass classDescriptor) {
    if (classDescriptor == null) {
        return new String[0];
    }
    final ObjectStreamField[] fields = classDescriptor.getFields();
    final String[] fieldNames = new String[fields.length];
    for (int i = 0; i < fieldNames.length; i++) {
        fieldNames[i] = fields[i].getName();
    }
    return fieldNames;
}
项目:AnalyzerBeans    文件:ChangeAwareObjectInputStream.java   
private String[] getFieldNames(ObjectStreamClass classDescriptor) {
    if (classDescriptor == null) {
        return new String[0];
    }
    final ObjectStreamField[] fields = classDescriptor.getFields();
    final String[] fieldNames = new String[fields.length];
    for (int i = 0; i < fieldNames.length; i++) {
        fieldNames[i] = fields[i].getName();
    }
    return fieldNames;
}
项目:cn1    文件:CodeSourceTest.java   
public void testSerilizationDescriptor() throws Exception {

        // Regression for HARMONY-2787
        ObjectStreamClass objectStreamClass = ObjectStreamClass
                .lookup(CodeSource.class);
        ObjectStreamField objectStreamField = objectStreamClass
                .getField("location");
        assertEquals("Ljava/net/URL;", objectStreamField.getTypeString());
    }