Search in sources :

Example 6 with ObjectInputStreamFiltered

use of org.apache.openejb.core.ObjectInputStreamFiltered in project tomee by apache.

the class PojoSerializationTest method _testSpeed.

public void _testSpeed() throws Exception {
    final long start = System.currentTimeMillis();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);
    final Green green = new Green(1);
    green.init();
    final int count = 20000;
    for (int i = count; i > 0; i--) {
        out.writeObject(new PojoSerialization(green));
    }
    out.close();
    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream in = new ObjectInputStreamFiltered(bais);
    for (int i = count; i > 0; i--) {
        final Green actual = (Green) in.readObject();
        assertEquals(green, actual);
    }
    final long finish = System.currentTimeMillis();
    fail("" + (finish - start));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 7 with ObjectInputStreamFiltered

use of org.apache.openejb.core.ObjectInputStreamFiltered in project tomee by apache.

the class LocalBeanProxySerializationTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    assertNotNull(bean);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(bean);
    final ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream ois = new ObjectInputStreamFiltered(bis);
    final SampleLocalBean deserialized = (SampleLocalBean) ois.readObject();
    assertEquals(5, deserialized.add(2, 3));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 8 with ObjectInputStreamFiltered

use of org.apache.openejb.core.ObjectInputStreamFiltered in project tomee by apache.

the class SerializationOfTransactionRolledBackExceptionTest method deserialize.

private static Object deserialize(final byte[] serial) throws Exception {
    final ByteArrayInputStream bais = new ByteArrayInputStream(serial);
    final ObjectInputStream ois = new ObjectInputStreamFiltered(bais);
    return ois.readObject();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with ObjectInputStreamFiltered

use of org.apache.openejb.core.ObjectInputStreamFiltered in project tomee by apache.

the class SimplePassivater method activate.

@Override
public Object activate(final Object primaryKey) throws SystemException {
    try {
        final String filename = primaryKey.toString().replace(':', '=');
        final File sessionFile = new File(sessionDirectory, filename);
        if (sessionFile.exists()) {
            logger.info("Activating from file " + sessionFile);
            try (final InputStream source = IO.read(sessionFile);
                final ObjectInputStream ois = new ObjectInputStreamFiltered(source)) {
                final Object state = ois.readObject();
                if (!sessionFile.delete()) {
                    sessionFile.deleteOnExit();
                }
                return state;
            }
        } else {
            logger.info("Activation failed: file not found " + sessionFile);
            return null;
        }
    } catch (final Exception t) {
        logger.info("Activation failed ", t);
        throw new SystemException(t);
    }
}
Also used : SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) File(java.io.File) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException) ObjectInputStream(java.io.ObjectInputStream)

Example 10 with ObjectInputStreamFiltered

use of org.apache.openejb.core.ObjectInputStreamFiltered in project tomee by apache.

the class Serializer method deserialize.

public static Object deserialize(final byte[] bytes) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = null;
    try {
        final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ois = new ObjectInputStreamFiltered(bais);
        return ois.readObject();
    } finally {
        if (ois != null) {
            ois.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamFiltered(org.apache.openejb.core.ObjectInputStreamFiltered) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)10 ObjectInputStreamFiltered (org.apache.openejb.core.ObjectInputStreamFiltered)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NotSerializableException (java.io.NotSerializableException)1 SystemException (org.apache.openejb.SystemException)1 Test (org.junit.Test)1