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));
}
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));
}
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();
}
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);
}
}
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();
}
}
}
Aggregations