Give the attached .lca a look. I think it gets the job done. It uses a script as follows:
import com.adobe.idp.Document;
Document document = patExecContext.getProcessDataDocumentValue("/process_data/myDocument");
String str = document.toString();
byte[] byteArray = str.getBytes();
patExecContext.setProcessDataIntValue("/process_data/@byteArrayLength",byteArray.length);
patExecContext.setProcessDataValue("/process_data/myObject",byteArray);
Steve