Search in sources :

Example 1 with ObjectInputStreamFiltered

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

the class LocalReferenceSerializationTest method copy.

private static <T> T copy(final T bean) throws IOException, ClassNotFoundException {
    assertNotNull(bean);
    ServerFederation.setApplicationServer(new TestApplicationServer());
    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);
    return (T) ois.readObject();
}
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 2 with ObjectInputStreamFiltered

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

the class PojoSerializationTest method test.

public void test() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);
    final Green green = new Green(1);
    green.init();
    out.writeObject(new PojoSerialization(green));
    out.close();
    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream in = new ObjectInputStreamFiltered(bais);
    final Green actual = (Green) in.readObject();
    assertEquals(green, actual);
}
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 3 with ObjectInputStreamFiltered

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

the class PojoExternalizationTest 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 4 with ObjectInputStreamFiltered

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

the class EjbTimerImplSerializableTest 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 5 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)

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