use of java.io.ObjectStreamClass in project jdk8u_jdk by JetBrains.
the class ProxyClassDesc method run.
/**
* Write and read proxy class descriptors to/from a stream.
* Arguments: <# cycles>
*/
public long run(String[] args) throws Exception {
int ncycles = Integer.parseInt(args[0]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout = new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin = new ObjectInputStream(sbuf.getInputStream());
ObjectStreamClass[] descs = genDescs();
// warmup
doReps(oout, oin, sbuf, descs, 1);
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, descs, ncycles);
return System.currentTimeMillis() - start;
}
use of java.io.ObjectStreamClass in project jdk8u_jdk by JetBrains.
the class ProxyClassDesc method genDescs.
/**
* Generate proxy class descriptors.
*/
ObjectStreamClass[] genDescs() {
ClassLoader ldr = ProxyClassDesc.class.getClassLoader();
Class[] ifaces = new Class[3];
Class[] a = new Class[] { A1.class, A2.class, A3.class, A4.class, A5.class };
Class[] b = new Class[] { B1.class, B2.class, B3.class, B4.class, B5.class };
Class[] c = new Class[] { C1.class, C2.class, C3.class, C4.class, C5.class };
ObjectStreamClass[] descs = new ObjectStreamClass[a.length * b.length * c.length];
int n = 0;
for (int i = 0; i < a.length; i++) {
ifaces[0] = a[i];
for (int j = 0; j < b.length; j++) {
ifaces[1] = b[j];
for (int k = 0; k < c.length; k++) {
ifaces[2] = c[k];
Class proxyClass = Proxy.getProxyClass(ldr, ifaces);
descs[n++] = ObjectStreamClass.lookup(proxyClass);
}
}
}
return descs;
}
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());
}
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());
}
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());
}
Aggregations