Search in sources :

Example 1 with Documents

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();
}
Also used : Documents(org.jbpm.document.Documents) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Document(org.jbpm.document.Document)

Example 2 with Documents

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;
}
Also used : DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Documents(org.jbpm.document.Documents) Document(org.jbpm.document.Document)

Example 3 with 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());
}
Also used : Documents(org.jbpm.document.Documents) Test(org.junit.Test)

Example 4 with Documents

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());
}
Also used : Documents(org.jbpm.document.Documents) Document(org.jbpm.document.Document) Test(org.junit.Test)

Aggregations

Documents (org.jbpm.document.Documents)4 Document (org.jbpm.document.Document)3 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)1