Something like this should work:
JCas jcas1 = …
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream docOS = new ObjectOutputStream(buffer);
CASCompleteSerializer serializerOut =
Serialization.serializeCASComplete(jcas1.getCasImpl());
docOS.writeObject(serializerOut);
docOS.close();
JCas jcas2 = …
ObjectInputStream is = new ObjectInputStream(new
ByteArrayInputStream(buffer.toByteArray()));
CASCompleteSerializer serializerIn = (CASCompleteSerializer) is.readObject();
Serialization.deserializeCASComplete(serializerIn, (CASImpl)
jcas2.getCasImpl());
You could try without the buffer and just passing the seralizerOut as
serializerIn, but I don't
know if that works because I don't know if the internal data structures are
copied to the target
CAS or if they are directly injected.
-- Richard
Am 04.07.2013 um 15:35 schrieb Bojan Janisch <[email protected]>:
> Hey Richard,
>
> I've tried your way, but getting NullPointerException over
> NullPointerException at the merging.
>
> Exception in thread "ECJ Evaluation Thread 0" java.lang.NullPointerException
> at
> org.apache.uima.cas.impl.LinearTypeOrderBuilderImpl$TotalTypeOrder.<init>(LinearTypeOrderBuilderImpl.java:85)
> at
> org.apache.uima.cas.impl.LinearTypeOrderBuilderImpl$TotalTypeOrder.<init>(LinearTypeOrderBuilderImpl.java:50)
> at
> org.apache.uima.cas.impl.LinearTypeOrderBuilderImpl.createTypeOrder(LinearTypeOrderBuilderImpl.java:291)
> at
> org.apache.uima.cas.impl.CASMgrSerializer.getIndexRepository(CASMgrSerializer.java:462)
> at org.apache.uima.cas.impl.CASImpl.reinit(CASImpl.java:1079)
> at org.apache.uima.cas.impl.CASImpl.reinit(CASImpl.java:1071)
> at
> org.apache.uima.cas.impl.Serialization.deserializeCASComplete(Serialization.java:57)
> at rulevolution.utils.JCasUtils.cloneJCas(JCasUtils.java:257)
> at rulevolution.utils.JCasUtils.copyCasPool(JCasUtils.java:212)
> at rulevolution.RulEvolution.evaluate(RulEvolution.java:156)
> at ec.simple.SimpleEvaluator.evalPopChunk(SimpleEvaluator.java:259)
> at
> ec.simple.SimpleEvaluator$SimpleEvaluatorThreadCG.run(SimpleEvaluator.java:341)
> at ec.util.ThreadPool$PoolThread.run(ThreadPool.java:57)
>
>
> Do you or anybody else know where my mistake is? Here's the Code I've
> programmed for cloning:
>
> public static JCas cloneJCas(JCas aJCas){
> JCas jcas = null;
> try {
> jcas =
> UIMATypeSystemUtils.getEmptyCasFromTypeSystem(AbstractDeployer.TYPESYSTEM).getJCas();
>
> CASCompleteSerializer complete = new CASCompleteSerializer();
> complete.setCasSerializer(new CASSerializer());
> complete.setCasMgrSerializer(new CASMgrSerializer());
>
> complete.getCASMgrSerializer().addTypeSystem(aJCas.getCasImpl().getTypeSystemImpl());
> complete.getCASSerializer().addCAS(aJCas.getCasImpl());
> byte[] aBytes = SerializationUtils.serialize(complete);
>
>
> deserializeCASComplete((CASCompleteSerializer)SerializationUtils.deserialize(aBytes),
> jcas.getCasImpl());
> }
> ....
>
> return jcas;
> }
>
> The method which throws the exception:
>
> private TotalTypeOrder(int[] typeList, TypeSystem ts) {
> super();
> TypeSystemImpl tsi = (TypeSystemImpl) ts;
> this.order = typeList;
> this.typeCodeToOrder = new int[this.order.length +
> tsi.getSmallestType()]; //Thats the line I get the exception
> for (int i = 0; i < this.order.length; i++) {
> this.typeCodeToOrder[this.order[i]] = i;
> }
> }
>
>
> I appreciate any help.
>
> Greetings
>
> Bojan