本文整理汇总了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;
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}