use of java.io.ObjectStreamField 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());
}
use of java.io.ObjectStreamField in project j2objc by google.
the class MyObjectInputStream method test_getTypeString.
/**
* 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;");
}
use of java.io.ObjectStreamField 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);
}
use of java.io.ObjectStreamField in project wildfly by wildfly.
the class ValueAnalysis method doAnalyze.
protected void doAnalyze() throws RMIIIOPViolationException {
super.doAnalyze();
if (cls == String.class)
throw IIOPLogger.ROOT_LOGGER.cannotAnalyzeStringType();
if (cls == Class.class)
throw IIOPLogger.ROOT_LOGGER.cannotAnalyzeClassType();
if (Remote.class.isAssignableFrom(cls))
throw IIOPLogger.ROOT_LOGGER.valueTypeCantImplementRemote(cls.getName(), "1.2.4");
if (cls.getName().indexOf('$') != -1)
throw IIOPLogger.ROOT_LOGGER.valueTypeCantBeProxy(cls.getName());
externalizable = Externalizable.class.isAssignableFrom(cls);
if (!externalizable) {
// Look for serialPersistentFields field.
Field spf = null;
try {
spf = cls.getField("serialPersistentFields");
} catch (NoSuchFieldException ex) {
// ignore
}
if (spf != null) {
// Right modifiers?
int mods = spf.getModifiers();
if (!Modifier.isFinal(mods) || !Modifier.isStatic(mods) || !Modifier.isPrivate(mods))
// wrong modifiers
spf = null;
}
if (spf != null) {
// Right type?
Class type = spf.getType();
if (type.isArray()) {
type = type.getComponentType();
if (type != ObjectStreamField.class)
// Array of wrong type
spf = null;
} else
// Wrong type: Not an array
spf = null;
}
if (spf != null) {
// Get this constant
try {
serialPersistentFields = (ObjectStreamField[]) spf.get(null);
} catch (IllegalAccessException ex) {
throw IIOPLogger.ROOT_LOGGER.unexpectedException(ex);
}
// Mark this in the fields array
for (int i = 0; i < fields.length; ++i) {
if (fields[i] == spf) {
f_flags[i] |= F_SPFFIELD;
break;
}
}
}
// Look for a writeObject Method
Method wo = null;
try {
wo = cls.getMethod("writeObject", new Class[] { java.io.OutputStream[].class });
} catch (NoSuchMethodException ex) {
// ignore
}
if (// Right return type?
wo != null && wo.getReturnType() != Void.TYPE) {
// Wrong return type
wo = null;
}
if (wo != null) {
// Right modifiers?
int mods = wo.getModifiers();
if (!Modifier.isPrivate(mods))
// wrong modifiers
wo = null;
}
if (wo != null) {
// Right arguments?
Class[] paramTypes = wo.getParameterTypes();
if (paramTypes.length != 1)
// Bad number of parameters
wo = null;
else if (paramTypes[0] != java.io.OutputStream.class)
// Bad parameter type
wo = null;
}
if (wo != null) {
// We have the writeObject() method.
hasWriteObjectMethod = true;
// Mark this in the methods array
for (int i = 0; i < methods.length; ++i) {
if (methods[i] == wo) {
m_flags[i] |= M_WRITEOBJECT;
break;
}
}
}
}
// Map all fields not flagged constant or serialPersistentField.
SortedSet m = new TreeSet(new ValueMemberComparator());
for (int i = 0; i < fields.length; ++i) {
if (f_flags[i] != 0)
// flagged
continue;
int mods = fields[i].getModifiers();
if (Modifier.isStatic(mods) || Modifier.isTransient(mods))
// don't map this
continue;
ValueMemberAnalysis vma;
vma = new ValueMemberAnalysis(fields[i].getName(), fields[i].getType(), Modifier.isPublic(mods));
m.add(vma);
}
members = new ValueMemberAnalysis[m.size()];
members = (ValueMemberAnalysis[]) m.toArray(members);
// Get superclass analysis
Class superClass = cls.getSuperclass();
if (superClass == java.lang.Object.class)
superClass = null;
if (superClass == null)
superAnalysis = null;
else {
superAnalysis = getValueAnalysis(superClass);
}
if (!Serializable.class.isAssignableFrom(cls))
abstractValue = true;
fixupCaseNames();
}
Aggregations