/** * Serialize in compressed binary with type filtering * This method can use type filtering to omit sending those types and/or features not present in the target type system. * - To omit type filtering, use null for the target type system * It also only sends those feature structures which are reachable either from an index or references from other reachable feature structures. * * @param cas the CAS to serialize * @param out an OutputStream, a DataOutputStream, or a File * @param includeTS true to serialize the type system * @param includeTSI true to serialize the type system and the indexes definition * @return information to be used on subsequent serializations (to save time) or deserializations (for receiving delta CASs), or reserializations (if sending delta CASs) * @throws IOException if IO exception * @throws ResourceInitializationException if target type system is incompatible with this CAS's type system */ public static ReuseInfo serializeWithCompression(CAS cas, Object out, boolean includeTS, boolean includeTSI) throws IOException, ResourceInitializationException { BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, null, includeTS, includeTSI); bcs.serialize(out); return bcs.getReuseInfo(); }
/** * Deserialize a CAS, in various binary formats, into an existing CAS * Note: this form supports deserializing the following binary representations: * - compressed, type filtering (form 6), delta and not-delta. * * @param cas the CAS to deserialize into. If the incoming representation is a Delta Cas, then the receiving CAS is not reset, but is added to. * @param istream the input stream * @param tgtTypeSystem The typeSystem of the serialized form of the CAS; must be compatible with the type system of the receiving cas. * @param reuseInfo If delta CAS is being received and form 6 compression is being used, then this must be the reuseInfo captured when the * original CAS (being updated by the delta coming in) was sent out. * @return The instance of BinaryCasSerDes6 used for deserialization * @throws IOException if IO exception * @throws ResourceInitializationException if the target type system and the CAS's type system can't be merged */ public static BinaryCasSerDes6 deserializeCAS(CAS cas, InputStream istream, TypeSystem tgtTypeSystem, ReuseInfo reuseInfo) throws IOException, ResourceInitializationException { BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, null, (TypeSystemImpl) tgtTypeSystem, reuseInfo); bcs.deserialize(istream); return bcs; }
private long readDouble() throws IOException { int exponent = readVnumber(double_Exponent_dis); if (exponent == 0) { return 0L; } long mants = readVlong(double_Mantissa_Sign_dis); return decodeDouble(mants, exponent); }
/** * Delta Serialize in compressed form, with type filtering * This method can use type filtering to omit sending those types and/or features not present in the target type system. * - To omit type filtering, use null for the target type system * It also only sends those feature structures which are reachable either from an index or references from other reachable feature structures. * * @param cas the CAS to serialize * @param out an OutputStream, a DataOutputStream, or a File * @param tgtTypeSystem null or a target TypeSystem, which must be mergable with this CAS's type system * @param mark null or where the mark is in the CAS. If not null, indicates doing a delta CAS serialization * @param reuseInfo if mark is not null, this parameter is required * and must have been computed when the original deserialization (of the CAS now being serialized as a delta CAS) was done * @throws IOException if IO exception * @throws ResourceInitializationException if the target type system and the CAS's type system can't be merged */ public static void serializeWithCompression(CAS cas, Object out, TypeSystem tgtTypeSystem, Marker mark, ReuseInfo reuseInfo) throws IOException, ResourceInitializationException { BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, (MarkerImpl) mark, (TypeSystemImpl) tgtTypeSystem, reuseInfo); bcs.serialize(out); }
setupOutputStreams(out); System.out.println(printCasInfo(cas)); sm.origAuxBytes = cas.getByteHeap().getSize(); sm.origAuxShorts = cas.getShortHeap().getSize() * 2; processIndexedFeatureStructures(cas, false /* compute ref'd FSs, no write */); totalMappedHeapSize = initFsStartIndexes(); if (heapStart == 0) { writeStringInfo(); writeVnumber(control_dos, totalMappedHeapSize); if (doMeasurements) { sm.statDetails[Slot_MainHeap.ordinal()].original = (1 + heapEnd - heapStart) * 4; writeVnumber(typeCode_dos, mappedTypeCode); serializeHeapStoredArray(iHeap); } else if (typeInfo.isArray) { serializeNonHeapStoredArray(iHeap); } else { if (isTypeMapping) { serializeByKind(iHeap, featOffsetInSrc); serializeByKind(iHeap, i);
setupReadStreams(); int lenCmnStrs = readVnumber(strChars_dis); readCommonString = new String[lenCmnStrs]; for (int i = 0; i < lenCmnStrs; i++) { int heapUsedInTarget = readVnumber(control_dis); final Heap heapObj = cas.getHeap(); final int tgtTypeCode = readVnumber(typeCode_dis); // get type code final int srcTypeCode = isTypeMapping ? typeMapper.mapTypeCodeTgt2Src(tgtTypeCode) : tgtTypeCode; if (storeIt) { typeInfo = tgtTypeInfo; initPrevIntValue(iHeap); // note "typeInfo" a hidden parameter - ugly... readHeapStoredArray(iHeap, storeIt, heapObj, srcTypeCode); } else if (typeInfo.isArray) { if (storeIt) { readNonHeapStoredArray(iHeap, storeIt); } else { if (storeIt) { readByKind(iHeap, featOffsetInSrc, kind, storeIt); readByKind(iHeap, i, kind, storeIt); targetHeapUsed += incrToNextFs(heap, iHeap, tgtTypeInfo); // typeInfo is target type info
: (f6 != null && f6.getTgtTs() != null) ? f6.getTgtTs() // this is the ts passed in via BinaryCasSerDes6 constructor ? new BinaryCasSerDes6(f6, ts_for_decoding) : new BinaryCasSerDes6(this, ts_for_decoding); bcsd.deserializeAfterVersion(dis, delta, AllowPreexistingFS.allow); return h.typeSystemIndexDefIncluded ? SerialFormat.COMPRESSED_FILTERED_TSI BinaryCasSerDes6.skipBytes(dis, align); BinaryCasSerDes6.skipBytes(dis, align);
case COMPRESSED_FILTERED: ByteArrayInputStream bais = new ByteArrayInputStream(binarySource); reuseInfo = Serialization.deserializeCAS(cas, bais, endpoint.getTypeSystemImpl(), null).getReuseInfo(); break; default:
private int readString(boolean storeIt) throws IOException { final int length = decodeIntSign(readVnumber(strLength_dis)); if (debugEOF) { final int offset = readVnumber(strOffset_dis); final int segmentIndex = (only1CommonString) ? 0 : readVnumber(strSeg_dis); if (debugEOF) { System.out.format("readString offset = %,d%n", offset);
addStringFromFS(srcTypeInfo, iSrcHeap, tCode); final int deltaTgtHeap = incrToNextFs(heap, iSrcHeap, tgtTypeInfo); nextTgtHeap += deltaTgtHeap;
private long decodeDouble(long mants, int exponent) { exponent = decodeIntSign(exponent); if (exponent > 0) { exponent --; } exponent = exponent + 1023; long r = ((long)((exponent) & 0x7ff)) << 52; final boolean isNegative = (1 == (mants & 1)); mants = Long.reverse(mants >>> 1) >>> 12; r = r | mants | (isNegative ? 0x8000000000000000L : 0); return r; }
public byte[] serializeCasToBinary6(CAS aCAS) throws Exception { ByteArrayOutputStream fos = null; fos = new ByteArrayOutputStream(); BinaryCasSerDes6 bcs = new BinaryCasSerDes6(aCAS); bcs.serialize(fos); return fos.toByteArray(); }
/** * Serialize in compressed binary with type filtering * This method can use type filtering to omit sending those types and/or features not present in the target type system. * - To omit type filtering, use null for the target type system * It also only sends those feature structures which are reachable either from an index or references from other reachable feature structures. * * @param cas the CAS to serialize * @param out an OutputStream, a DataOutputStream, or a File * @param tgtTypeSystem null or a target TypeSystem, which must be mergable with this CAS's type system * @return information to be used on subsequent serializations (to save time) or deserializations (for receiving delta CASs), or reserializations (if sending delta CASs) * @throws IOException if IO exception * @throws ResourceInitializationException if target type system is incompatible with this CAS's type system */ public static ReuseInfo serializeWithCompression(CAS cas, Object out, TypeSystem tgtTypeSystem) throws IOException, ResourceInitializationException { BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, (TypeSystemImpl) tgtTypeSystem); bcs.serialize(out); return bcs.getReuseInfo(); }
public byte[] serializeCasToBinary6(CAS aCAS, Marker aMark, ReuseInfo reuseInfo) throws Exception { ByteArrayOutputStream fos = null; fos = new ByteArrayOutputStream(); BinaryCasSerDes6 bcs = new BinaryCasSerDes6(aCAS, (MarkerImpl) aMark, null, reuseInfo); bcs.serialize(fos); return fos.toByteArray(); }
/** * Deserialize a CAS, in various binary formats, into an existing CAS * Note: this form supports deserializing the following binary representations: * - compressed, type filtering (form 6), delta and not-delta. * * @param cas the CAS to deserialize into. If the incoming representation is a Delta Cas, then the receiving CAS is not reset, but is added to. * @param istream the input stream * @param tgtTypeSystem The typeSystem of the serialized form of the CAS; must be compatible with the type system of the receiving cas. * @param reuseInfo If delta CAS is being received and form 6 compression is being used, then this must be the reuseInfo captured when the * original CAS (being updated by the delta coming in) was sent out. * @param allowPreexisting used to control what happens when a delta cas is modifying Feature Structures below the line * @return The instance of BinaryCasSerDes6 used for deserialization * @throws IOException if IO exception * @throws ResourceInitializationException if the target type system and the CAS's type system can't be merged */ public static BinaryCasSerDes6 deserializeCAS(CAS cas, InputStream istream, TypeSystem tgtTypeSystem, ReuseInfo reuseInfo, AllowPreexistingFS allowPreexisting) throws IOException, ResourceInitializationException { BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, null, (TypeSystemImpl) tgtTypeSystem, reuseInfo); bcs.deserialize(istream, allowPreexisting); return bcs; }
public byte[] serializeCasToBinary6(CAS aCAS, CacheEntry entry, TypeSystemImpl tgtTs) throws Exception { ByteArrayOutputStream fos = null; fos = new ByteArrayOutputStream(); BinaryCasSerDes6 bcs = new BinaryCasSerDes6(aCAS, tgtTs); bcs.serialize(fos); entry.setCompress6ReuseInfo(bcs.getReuseInfo()); return fos.toByteArray(); }
break; case COMPRESSED_FILTERED: BinaryCasSerDes6 bcs = new BinaryCasSerDes6(cas, (MarkerImpl) cacheEntry.getMarker(), endpointWithTimer.getTypeSystemImpl(), cacheEntry.getCompress6ReuseInfo()); bcs.deserialize(istream, AllowPreexistingFS.allow); break; case XMI:
BinaryCasSerDes6 bcs = new BinaryCasSerDes6(aCAS, this.getRemoteTypeSystem()); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); bcs.serialize(baos); requestToCache.setCompress6ReuseInfo(bcs.getReuseInfo()); msg.put(AsynchAEMessage.CAS, baos.toByteArray()); break;