use of org.jbpm.document.Documents in project jbpm by kiegroup.
the class DocumentsMarshallingStrategy method marshal.
public byte[] marshal(Context ctx, ObjectOutputStream objectOutputStream, Object o) throws IOException {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(buff)) {
Documents documents = (Documents) o;
// Write the number of documents in the list.
oos.writeInt(documents.getDocuments().size());
for (Document nextDocument : documents.getDocuments()) {
// Use the DocumentMarshallingStrategy to marshal individual documents.
byte[] nextMarshalledDocument = docMarshallingStrategy.marshal(ctx, objectOutputStream, nextDocument);
oos.writeInt(nextMarshalledDocument.length);
oos.write(nextMarshalledDocument);
// Need to call reset on the stream in order for the Document bytes to be written correctly.
oos.reset();
}
}
return buff.toByteArray();
}
use of org.jbpm.document.Documents in project jbpm by kiegroup.
the class DocumentsMarshallingStrategy method unmarshal.
public Object unmarshal(Context ctx, ObjectInputStream objectInputStream, byte[] object, ClassLoader classLoader) throws IOException, ClassNotFoundException {
Documents documents = new Documents();
try (DroolsObjectInputStream is = new DroolsObjectInputStream(new ByteArrayInputStream(object), classLoader)) {
// first we read the size of the list we've stored.
int size = is.readInt();
for (int i = 0; i < size; i++) {
// Use the DocumentMarshallingStrategy to unmarshal the individual documents.
int length = is.readInt();
byte[] marshalledDocument = new byte[length];
is.readFully(marshalledDocument);
Document nextDocument = (Document) docMarshallingStrategy.unmarshal(ctx, objectInputStream, marshalledDocument, classLoader);
documents.addDocument(nextDocument);
}
}
return documents;
}
use of org.jbpm.document.Documents in project jbpm by kiegroup.
the class DocumentsMarshallingStrategyTest method testNoDocumentsMarshallUnmarshall.
@Test
public void testNoDocumentsMarshallUnmarshall() throws IOException, ClassNotFoundException {
Documents docs = new Documents();
byte[] marshalledDocuments = docsMarshallingStrategy.marshal(null, null, docs);
Documents unmarshalledDocuments = (Documents) docsMarshallingStrategy.unmarshal(null, null, marshalledDocuments, this.getClass().getClassLoader());
assertEquals(docs.getDocuments().size(), unmarshalledDocuments.getDocuments().size());
}
use of org.jbpm.document.Documents in project jbpm by kiegroup.
the class DocumentsMarshallingStrategyTest method testMarshallUnmarshall.
@Test
public void testMarshallUnmarshall() throws IOException, ClassNotFoundException {
List<Document> documents = getDocuments();
Documents docs = new Documents(documents);
byte[] marshalledDocs = docsMarshallingStrategy.marshal(null, null, docs);
Documents unmarshalledDocs = (Documents) docsMarshallingStrategy.unmarshal(null, null, marshalledDocs, this.getClass().getClassLoader());
assertEquals(docs.getDocuments().size(), unmarshalledDocs.getDocuments().size());
List<Document> unmarshalledDocumentsList = unmarshalledDocs.getDocuments();
assertEquals(documents.size(), unmarshalledDocumentsList.size());
assertEquals(unmarshalledDocumentsList.get(0).getName(), docs.getDocuments().get(0).getName());
assertEquals(unmarshalledDocumentsList.get(0).getLink(), docs.getDocuments().get(0).getLink());
assertEquals(unmarshalledDocumentsList.get(1).getName(), docs.getDocuments().get(1).getName());
assertEquals(unmarshalledDocumentsList.get(1).getLink(), docs.getDocuments().get(1).getLink());
}
Aggregations