public static void readSerializedCas(CAS aCas, File aFile) throws IOException { try (ObjectInputStream is = new ObjectInputStream(new FileInputStream(aFile))) { CASCompleteSerializer serializer = (CASCompleteSerializer) is.readObject(); deserializeCASComplete(serializer, (CASImpl) aCas); // Initialize the JCas sub-system which is the most often used API in DKPro Core // components aCas.getJCas(); } catch (CASException | ClassNotFoundException e) { throw new IOException(e); } } }
/** * Creates a new <code>SerializableAnalysisProcessData</code> that contains the given * <code>CAS</code> and <code>ProcessTrace</code>. * * @param aCAS * the CAS whose state will be extracted into this object * @param aProcessTrace * the process trace object. This may be null, if no process trace is available. (For * example, ProcessTrace data may often be returned from a service but not passed to the * service.) */ public ServiceDataCargo(CAS aCAS, ProcessTrace aProcessTrace) { mCasSer = Serialization.serializeCASComplete((CASMgr) aCAS); mProcessTrace = aProcessTrace; }
public static void deserializeCAS(CAS cas, InputStream in) { Serialization.deserializeCAS(cas, in); }
public CASCompleteSerializer(CASImpl cas) { this(); this.casMgrSer = Serialization.serializeCASMgr(cas); this.casSer = Serialization.serializeCAS(cas); }
public static void writeTypeSystem(CAS aCas, OutputStream aOS, boolean includeIndexDefs) throws IOException { writeJavaObject(includeIndexDefs ? Serialization.serializeCASMgr((CASImpl) aCas) : Serialization.serializeCASMgrTypeSystemOnly((CASImpl) aCas) , aOS); }
/** * Unmarshalls the CAS data in this <code>ServiceDataCargo</code> into an existing * <code>CAS</code> instance. The data in the exsiting CAS will be replaced by the CAS data in * this object. * * @param aCas the CAS to unmarshal into * @param aReplaceCasTypeSystem if true, assumes serialized data contains the type system * @throws CASException passthru */ public void unmarshalCas(CAS aCas, boolean aReplaceCasTypeSystem) throws CASException { CASMgr casMgr = (CASMgr) aCas; if (aReplaceCasTypeSystem) { Serialization.deserializeCASComplete(mCasSer, casMgr); } else { Serialization.createCAS(casMgr, mCasSer.getCASSerializer()); } }
/** * Load the contents from the source CAS, upgrade it to the target type system and write the * results to the target CAS. An in-place upgrade can be achieved by using the same CAS as * source and target. */ private void upgradeCas(CAS aSourceCas, CAS aTargetCas, TypeSystemDescription aTargetTypeSystem) throws UIMAException, IOException { // Save source CAS type system (do this early since we might do an in-place upgrade) TypeSystem sourceTypeSystem = aSourceCas.getTypeSystem(); // Save source CAS contents ByteArrayOutputStream serializedCasContents = new ByteArrayOutputStream(); Serialization.serializeWithCompression(aSourceCas, serializedCasContents, sourceTypeSystem); // Re-initialize the target CAS with new type system CAS tempCas = JCasFactory.createJCas(aTargetTypeSystem).getCas(); CASCompleteSerializer serializer = Serialization.serializeCASComplete((CASImpl) tempCas); Serialization.deserializeCASComplete(serializer, (CASImpl) aTargetCas); // Leniently load the source CAS contents into the target CAS CasIOUtils.load(new ByteArrayInputStream(serializedCasContents.toByteArray()), aTargetCas, sourceTypeSystem); // Make sure JCas is properly initialized too aTargetCas.getJCas(); }
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());
break; case SERIALIZED: writeJavaObject(Serialization.serializeCAS(aCas), docOS); break; case SERIALIZED_TSI: writeJavaObject(Serialization.serializeCASComplete((CASMgr) aCas), docOS); typeSystemWritten = true; // Embedded type system break; case BINARY: // Java-serialized CAS without type system serializeCAS(aCas, docOS); break; case BINARY_TSI: // Java-serialized CAS without type system break; case COMPRESSED: // Binary compressed CAS without type system (form 4) serializeWithCompression(aCas, docOS); break; case COMPRESSED_TSI: // Binary compressed CAS without type system (form 4) break; case COMPRESSED_FILTERED: // Binary compressed CAS (form 6) serializeWithCompression(aCas, docOS, false, false); break; case COMPRESSED_FILTERED_TS: serializeWithCompression(aCas, docOS, true, false); typeSystemWritten = true; // Embedded type system break; case COMPRESSED_FILTERED_TSI: serializeWithCompression(aCas, docOS, false, true);
public void process(JCas currentJCas) throws AnalysisEngineProcessException { ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); ByteArrayInputStream inputStream; try { // Serialization.serializeCAS(currentJCas.getCas(), byteOutputStream); BinaryCasSerDes6.ReuseInfo reuseInfo = Serialization.serializeWithCompression(currentJCas.getCas(), byteOutputStream, true, true); inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray()); CASMgr cas = CASFactory.createCAS(currentJCas.getTypeSystem()); Serialization.deserializeCAS(jCas.getCas(), inputStream, currentJCas.getTypeSystem(), reuseInfo); } catch (IOException e) { e.printStackTrace(); } catch (UIMAException e) { e.printStackTrace(); } }
CASCompleteSerializer serializer = (CASCompleteSerializer) SerializationUtils .deserialize(casBytes); Serialization.deserializeCASComplete(serializer, (CASMgr) cas); CASSerializer responseSerializer = Serialization.serializeCAS(cas); byte[] responseCasBytes = SerializationUtils.serialize(responseSerializer); responseFrame.fsetTrueBinary("BinaryCAS", responseCasBytes);
private void storeCas(JCas jcas, final long endTime, final String key) throws IOException, SAXException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serialization.serializeWithCompression(jcas.getCas(), baos); final byte[] bytes = baos.toByteArray(); persistence.storeCas(bytes, ExecutionStatus.SUCCESS, endTime, key); }
public byte[] serializeCasToBinary(CAS aCAS) throws Exception { ByteArrayOutputStream fos = null; try { fos = new ByteArrayOutputStream(); Serialization.serializeCAS(aCAS, fos); return fos.toByteArray(); } catch (Exception e) { throw e; } finally { if (fos != null) { fos.close(); } } }
private void writeTypeSystem(CAS cas, DataOutputStream aOS) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(512); DeflaterOutputStream dos = new DeflaterOutputStream(bos); ObjectOutputStream typeOS = new ObjectOutputStream(dos); CASMgrSerializer casMgrSerializer; try { casMgrSerializer = serializeCASMgr(cas.getJCas().getCasImpl()); typeOS.writeObject(casMgrSerializer); } catch (CASException e) { throw new IOException(e); } typeOS.flush(); dos.flush(); dos.finish(); aOS.writeInt(bos.size()); bos.writeTo(aOS); aOS.flush(); } }
/** * Load the contents from the source CAS, upgrade it to the target type system and write the * results to the target CAS. An in-place upgrade can be achieved by using the same CAS as * source and target. */ private void upgradeCas(CAS aSourceCas, CAS aTargetCas, TypeSystemDescription aTargetTypeSystem) throws UIMAException, IOException { // Save source CAS type system (do this early since we might do an in-place upgrade) TypeSystem sourceTypeSystem = aSourceCas.getTypeSystem(); // Save source CAS contents ByteArrayOutputStream serializedCasContents = new ByteArrayOutputStream(); Serialization.serializeWithCompression(aSourceCas, serializedCasContents, sourceTypeSystem); // Re-initialize the target CAS with new type system CAS tempCas = JCasFactory.createJCas(aTargetTypeSystem).getCas(); CASCompleteSerializer serializer = Serialization.serializeCASComplete((CASImpl) tempCas); Serialization.deserializeCASComplete(serializer, (CASImpl) aTargetCas); // Leniently load the source CAS contents into the target CAS CasIOUtils.load(new ByteArrayInputStream(serializedCasContents.toByteArray()), aTargetCas, sourceTypeSystem); // Make sure JCas is properly initialized too aTargetCas.getJCas(); }
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());
@Override public void write(DataOutput out) throws IOException { ByteArrayOutputStream aOS = new ByteArrayOutputStream(400); DataOutputStream docOS = new DataOutputStream(aOS); try { serializeWithCompression(cas, docOS, cas.getTypeSystem()); docOS.flush(); docOS.close(); out.writeInt(aOS.size()); byte[] byteArray = aOS.toByteArray(); out.write(byteArray); } catch (CASRuntimeException e) { throw new IOException(e); } catch (ResourceInitializationException e) { throw new IOException(e); } }
public byte[] serializeCasToBinary(CAS aCAS, Marker aMark) throws Exception { ByteArrayOutputStream fos = null; try { fos = new ByteArrayOutputStream(); Serialization.serializeCAS(aCAS, fos, aMark); return fos.toByteArray(); } catch (Exception e) { throw e; } finally { if (fos != null) { fos.close(); } } }
CASMgrSerializer serializer = Serialization.serializeCASMgr((CASMgr) cas); engine.typeSystemInit(serializer);
CASCompleteSerializer serializer = serializeCASComplete(aJCas.getCasImpl()); deserializeCASComplete(serializer, (CASImpl) target.getCas());