当前位置: 首页>>代码示例>>Java>>正文


Java ObjectStreamField类代码示例

本文整理汇总了Java中java.io.ObjectStreamField的典型用法代码示例。如果您正苦于以下问题:Java ObjectStreamField类的具体用法?Java ObjectStreamField怎么用?Java ObjectStreamField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObjectStreamField类属于java.io包,在下文中一共展示了ObjectStreamField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPersistentFields

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:ValueType.java

示例2: test_specialTypes

import java.io.ObjectStreamField; //导入依赖的package包/类
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);
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:23,代码来源:ObjectStreamClassTest.java

示例3: test_getType_Deserialized

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:21,代码来源:ObjectStreamFieldTest.java

示例4: test_getType_MockObjectInputStream

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:21,代码来源:ObjectStreamFieldTest.java

示例5: test_getOffset

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());

    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:25,代码来源:ObjectStreamFieldTest.java

示例6: test_getType_Deserialized

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:ObjectStreamFieldTest.java

示例7: test_getType_MockObjectInputStream

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:ObjectStreamFieldTest.java

示例8: test_isPrimitive

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:ObjectStreamFieldTest.java

示例9: test_objectStreamClass_getFields

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:FileTest.java

示例10: doReadObject

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:29,代码来源:AbstractLegacyAwareInputRow.java

示例11: test_getType_Deserialized

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:ObjectStreamFieldTest.java

示例12: test_getType_MockObjectInputStream

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:ObjectStreamFieldTest.java

示例13: test_getType_Deserialized

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:21,代码来源:ObjectStreamFieldTest.java

示例14: test_getType_MockObjectInputStream

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:20,代码来源:ObjectStreamFieldTest.java

示例15: test_getFields

import java.io.ObjectStreamField; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:11,代码来源:ObjectStreamClassTest.java


注:本文中的java.io.ObjectStreamField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。