use of java.io.ObjectOutput in project drools by kiegroup.
the class ProcessContextTest method testProcessContextGetAssignment.
@Test
public void testProcessContextGetAssignment() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
assertNotNull(ksession);
CaseInformation caseInfo = new CaseInformation();
caseInfo.assign("owner", new OrganizationalEntity() {
@Override
public String getId() {
return "testUser";
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
});
ksession.insert(caseInfo);
ProcessContext processContext = new ProcessContext(ksession);
CaseAssignment caseAssignment = processContext.getCaseAssignment();
assertNotNull(caseAssignment);
Collection<OrganizationalEntity> forRole = caseAssignment.getAssignments("owner");
assertNotNull(forRole);
assertEquals(1, forRole.size());
}
use of java.io.ObjectOutput in project hibernate-orm by hibernate.
the class CriteriaCompilingTest method serializeDeserialize.
@SuppressWarnings({ "unchecked" })
private <T> T serializeDeserialize(T object) {
T serializedObject = null;
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(stream);
out.writeObject(object);
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream(serialized);
ObjectInputStream in = new ObjectInputStream(byteIn);
serializedObject = (T) in.readObject();
in.close();
byteIn.close();
} catch (Exception e) {
Assert.fail("Unable to serialize / deserialize the object: " + e.getMessage());
}
return serializedObject;
}
use of java.io.ObjectOutput in project hibernate-orm by hibernate.
the class EntityManagerTest method testSerializableException.
@Test
public void testSerializableException() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Query query = em.createQuery("SELECT p FETCH JOIN p.distributors FROM Item p");
query.getSingleResult();
} catch (IllegalArgumentException e) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(stream);
out.writeObject(e);
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream(serialized);
ObjectInputStream in = new ObjectInputStream(byteIn);
IllegalArgumentException deserializedException = (IllegalArgumentException) in.readObject();
in.close();
byteIn.close();
assertNull(deserializedException.getCause().getCause());
assertNull(e.getCause().getCause());
}
em.getTransaction().rollback();
em.close();
Exception e = new HibernateException("Exception", new NullPointerException("NPE"));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(stream);
out.writeObject(e);
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream(serialized);
ObjectInputStream in = new ObjectInputStream(byteIn);
HibernateException deserializedException = (HibernateException) in.readObject();
in.close();
byteIn.close();
assertNotNull("Arbitrary exceptions nullified", deserializedException.getCause());
assertNotNull(e.getCause());
}
use of java.io.ObjectOutput in project hibernate-orm by hibernate.
the class EntityManagerFactorySerializationTest method testEntityManagerFactorySerialization.
@Test
public void testEntityManagerFactorySerialization() throws Exception {
EntityManagerFactory entityManagerFactory = entityManagerFactory();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(stream);
out.writeObject(entityManagerFactory);
out.close();
byte[] serialized = stream.toByteArray();
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream(serialized);
ObjectInputStream in = new ObjectInputStream(byteIn);
EntityManagerFactory entityManagerFactory2 = (EntityManagerFactory) in.readObject();
in.close();
byteIn.close();
assertTrue("deserialized EntityManagerFactory should be the same original EntityManagerFactory instance", entityManagerFactory2 == entityManagerFactory);
}
use of java.io.ObjectOutput in project MusicDNA by harjot-oberai.
the class Lyrics method toBytes.
public byte[] toBytes() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(this);
out.close();
} finally {
bos.close();
}
return bos.toByteArray();
}
Aggregations