Search in sources :

Example 16 with ObjectStreamClass

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;
}
Also used : ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Example 17 with ObjectStreamClass

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;
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass) ObjectStreamClass(java.io.ObjectStreamClass)

Example 18 with ObjectStreamClass

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Example 19 with ObjectStreamClass

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectStreamField(java.io.ObjectStreamField) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass)

Example 20 with ObjectStreamClass

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());
}
Also used : ObjectStreamClass(java.io.ObjectStreamClass)

Aggregations

ObjectStreamClass (java.io.ObjectStreamClass)40 ObjectInputStream (java.io.ObjectInputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 IOException (java.io.IOException)11 ObjectOutputStream (java.io.ObjectOutputStream)8 ObjectStreamField (java.io.ObjectStreamField)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Serializable (java.io.Serializable)5 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 StreamCorruptedException (java.io.StreamCorruptedException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 SerializationException (krati.io.SerializationException)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileContext (org.apache.hadoop.fs.FileContext)1 Path (org.apache.hadoop.fs.Path)1