You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2016/08/17 20:54:21 UTC
svn commit: r1756689 - in /uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/impl/ main/java/org/apache/uima/util/
test/java/org/apache/uima/util/
Author: schor
Date: Wed Aug 17 20:54:21 2016
New Revision: 1756689
URL: http://svn.apache.org/viewvc?rev=1756689&view=rev
Log:
[UIMA-4685] add missing serialization of additional _TSI types (BINARY_TSI and COMPRESSED_TSI), consolidate all writing of TSI and TS in one utility, add some tests for BINARY_TSI and COMPRESSED_TSI
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java
uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes4.java Wed Aug 17 20:54:21 2016
@@ -79,6 +79,7 @@ import org.apache.uima.cas.Marker;
import org.apache.uima.cas.impl.FSsTobeAddedback.FSsTobeAddedbackSingle;
import org.apache.uima.internal.util.IntVector;
import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.CasIOUtils;
import org.apache.uima.util.impl.DataIO;
import org.apache.uima.util.impl.OptimizeStrings;
import org.apache.uima.util.impl.SerializationMeasures;
@@ -335,12 +336,18 @@ public class BinaryCasSerDes4 {
Serializer serializer = new Serializer(
casImpl, makeDataOutputStream(out), (MarkerImpl) trackingMark, sm,
- compressLevel, compressStrategy);
+ compressLevel, compressStrategy, false);
serializer.serialize();
return sm;
}
+ public void serializeWithTsi(CASImpl casImpl, Object out) throws IOException {
+ Serializer serializer = new Serializer(
+ casImpl, makeDataOutputStream(out), null, null, CompressLevel.Default, CompressStrat.Default, true);
+ serializer.serialize();
+ }
+
public SerializationMeasures serialize(AbstractCas cas, Object out, Marker trackingMark,
CompressLevel compressLevel) throws IOException {
return serialize(cas, out,trackingMark, compressLevel, CompressStrat.Default);
@@ -389,6 +396,7 @@ public class BinaryCasSerDes4 {
final private ByteHeap byteHeapObj;
final private boolean isDelta; // if true, there is a marker indicating the start spot(s)
+ final private boolean isTsi; // true to include the type system and indexes definition
final private boolean doMeasurement; // if true, doing measurements
final private ComprItemRefs fsStartIndexes = (CHANGE_FS_REFS_TO_SEQUENTIAL) ? new ComprItemRefs() : null;
final private int[] typeCodeHisto = new int[ts.getTypeArraySize()];
@@ -430,13 +438,15 @@ public class BinaryCasSerDes4 {
private Serializer(CASImpl cas, DataOutputStream serializedOut, MarkerImpl mark,
SerializationMeasures sm,
CompressLevel compressLevel,
- CompressStrat compressStrategy) {
+ CompressStrat compressStrategy,
+ boolean isTsi) {
this.cas = cas;
this.serializedOut = serializedOut;
this.mark = mark;
this.sm = sm;
this.compressLevel = compressLevel;
this.compressStrategy = compressStrategy;
+ this.isTsi = isTsi;
isDelta = (mark != null);
doMeasurement = (sm != null);
@@ -517,8 +527,13 @@ public class BinaryCasSerDes4 {
CommonSerDes.createHeader()
.form4()
.delta(isDelta)
+ .typeSystemIndexDefIncluded(isTsi)
.write(serializedOut);
+ if (isTsi) {
+ CasIOUtils.writeTypeSystem(cas, serializedOut, true);
+ }
+
if (TRACE_SER) System.out.println("Form4Ser start, delta: " + (isDelta ? "true" : "false"));
if (doMeasurement) {
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes6.java Wed Aug 17 20:54:21 2016
@@ -80,6 +80,7 @@ import org.apache.uima.internal.util.Int
import org.apache.uima.internal.util.rb_trees.Int2IntRBT;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.CasIOUtils;
import org.apache.uima.util.CasLoadMode;
import org.apache.uima.util.impl.DataIO;
import org.apache.uima.util.impl.OptimizeStrings;
@@ -701,11 +702,7 @@ public class BinaryCasSerDes6 {
.write(serializedOut);
if (isTsIncluded || isTsiIncluded) {
- ObjectOutputStream tsiOS = new ObjectOutputStream(serializedOut);
- tsiOS.writeObject(isTsiIncluded
- ? Serialization.serializeCASMgr((CASMgr) cas)
- : Serialization.serializeCASMgrTypeSystemOnly((CASMgr) cas));
- tsiOS.flush();
+ CasIOUtils.writeTypeSystem(cas, serializedOut, isTsiIncluded);
}
os = new OptimizeStrings(doMeasurements);
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Wed Aug 17 20:54:21 2016
@@ -1440,7 +1440,7 @@ public class CASImpl extends AbstractCas
final BinDeserSupport bds = new BinDeserSupport();
- CASMgrSerializer embeddedCasMgrSerializer = embeddedCasMgrSerializer = maybeReadEmbeddedTSI(h, dis);
+ CASMgrSerializer embeddedCasMgrSerializer = maybeReadEmbeddedTSI(h, dis);
if (!h.isForm6() || casLoadMode == CasLoadMode.REINIT) {
setupCasFromCasMgrSerializer(
@@ -1463,7 +1463,7 @@ public class CASImpl extends AbstractCas
if (h.form4) {
(new BinaryCasSerDes4(this.getTypeSystemImpl(), false)).deserialize(this, dis, delta);
- return SerialFormat.COMPRESSED;
+ return h.typeSystemIndexDefIncluded ? SerialFormat.COMPRESSED_TSI : SerialFormat.COMPRESSED;
}
if (h.form6) {
@@ -1700,7 +1700,7 @@ public class CASImpl extends AbstractCas
CASRuntimeException.BLOB_DESERIALIZATION, new String[] { msg });
throw exception;
}
- return SerialFormat.BINARY;
+ return h.typeSystemIndexDefIncluded ? SerialFormat.BINARY_TSI : SerialFormat.BINARY;
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASSerializer.java Wed Aug 17 20:54:21 2016
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.Marker;
+import org.apache.uima.util.CasIOUtils;
/**
* This object has 2 purposes.
@@ -204,6 +205,10 @@ public class CASSerializer implements Se
dos.writeInt(shdh.refHeap[i + StringHeapDeserializationHelper.CHAR_HEAP_STRLEN_OFFSET]);
}
}
+
+ void addTsiCAS(CASImpl cas, OutputStream ostream) {
+
+ }
/**
* Serializes the CAS data and writes it to the output stream.
@@ -234,18 +239,26 @@ public class CASSerializer implements Se
* @param ostream -
*/
public void addCAS(CASImpl cas, OutputStream ostream) {
-
- try {
+ addCAS(cas, ostream, false);
+ }
+
+ public void addCAS(CASImpl cas, OutputStream ostream, boolean includeTsi) {
+ try {
DataOutputStream dos = new DataOutputStream(ostream);
- // get the indexed FSs
- this.fsIndex = cas.getIndexedFSs();
-
// output the key and version number
CommonSerDes.createHeader()
.seqVer(1) // not a delta, set version 1 for UIMA-4743 to inform receiver that we can handle version 1 format
+ .typeSystemIndexDefIncluded(includeTsi)
.write(dos);
+
+ if (includeTsi) {
+ CasIOUtils.writeTypeSystem(cas, ostream, true);
+ }
+
+ // get the indexed FSs
+ this.fsIndex = cas.getIndexedFSs();
// output the FS heap
final int heapSize = cas.getHeap().getCellsUsed();
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasIOUtils.java Wed Aug 17 20:54:21 2016
@@ -19,7 +19,6 @@
package org.apache.uima.util;
import static org.apache.uima.cas.impl.Serialization.serializeCAS;
-import static org.apache.uima.cas.impl.Serialization.serializeCASMgr;
import static org.apache.uima.cas.impl.Serialization.serializeWithCompression;
import java.io.BufferedInputStream;
@@ -38,6 +37,7 @@ import org.apache.uima.cas.CASRuntimeExc
import org.apache.uima.cas.SerialFormat;
import org.apache.uima.cas.admin.CASMgr;
import org.apache.uima.cas.impl.AllowPreexistingFS;
+import org.apache.uima.cas.impl.BinaryCasSerDes4;
import org.apache.uima.cas.impl.CASCompleteSerializer;
import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.CASMgrSerializer;
@@ -45,6 +45,7 @@ import org.apache.uima.cas.impl.CASSeria
import org.apache.uima.cas.impl.CommonSerDes;
import org.apache.uima.cas.impl.CommonSerDes.Header;
import org.apache.uima.cas.impl.Serialization;
+import org.apache.uima.cas.impl.TypeSystemImpl;
import org.apache.uima.cas.impl.XCASSerializer;
import org.apache.uima.cas.impl.XmiCasSerializer;
import org.xml.sax.SAXException;
@@ -127,32 +128,28 @@ import org.xml.sax.SAXException;
* </ul>
*
* <p>Summary of APIs for saving:</p>
- * <pre style="padding-left: 30px;"><code>
- * save(aCAS, outputStream, aSerialFormat)
- * save(aCAS, outputStream, tsiOutputStream, aSerialFormat)
- * </code></pre>
+ * <p style="padding-left: 30px;">
+ * <code>save(aCAS, outputStream, aSerialFormat)</code><br></br>
+ * <code>save(aCAS, outputStream, tsiOutputStream, aSerialFormat)</code></p>
*
* <p>Summary of APIs for loading:</p>
- * <pre style="padding-left: 30px;"><code>
- * load(URL , CAS)
- * load(InputStream, CAS)
- * </code></pre>
- *
- * <pre style="padding-left: 30px;"><code>
- * // the second URL is for loading a separately-stored TSI
- * load(URL , URL , CAS, CasLoadMode)
- * load(InputStream, InputStream, CAS, CasLoadMode)
- * // lenient is used to set the CasLoadMode to LENIENT or DEFAULT
- * load(URL , URL , CAS, lenient)
- * load(InputStream, InputStream, CAS, lenient)
- * </code></pre>
+ * <p style="padding-left: 30px;">
+ * <code>load(aURL , aCas)</code><br></br>
+ * <code>load(inputStream, aCas)</code><br></br>
+ * <code>load(inputStream, tsiInputStream, aCas)</code></p>
+ * <p style="padding-left: 30px;">
+ * <code>load(aURL , tsiURL , aCAS, casLoadMode) - the second URL is for loading a separately-stored TSI</code><br></br>
+ * <code>load(inputStream, tsiInputStream, aCAS, aCasLoadMode)</code><br></br>
+ * <code>load(aURL , tsiURL , aCAS, lenient) - lenient is used to set the CasLoadMode to LENIENT or DEFAULT</code><br></br>
+ * <code>load(inputStream, tsiInputStream, aCAS, lenient)</code></p>
*/
public class CasIOUtils {
/**
* Loads a Cas from a URL source.
- * For SerialFormats ending with _TSI the type system and index definitions are reset except for Compressed Form 6.
+ * For SerialFormats ending with _TSI except for COMPRESSED_FILTERED_TSI,
+ * the CAS's type system and indexes definition are replaced.
* CasLoadMode is DEFAULT.
*
* @param casUrl
@@ -171,13 +168,12 @@ public class CasIOUtils {
/**
* Loads a CAS from a URL source. The format is determined from the content.
*
- * If the value of tsiUrl is non-null, it is read.
- * If values from both the tsiUrl and embedded values are available, the tsiUrl value is used.
+ * If the value of tsiUrl is null it is ignored.
*
* @param casUrl
* The url to deserialize the CAS from
* @param tsiUrl
- * The optional url to deserialize the type system and index definitions from
+ * null or an optional url to deserialize the type system and index definitions from
* @param aCAS
* The CAS that should be filled
* @param casLoadMode specifies how to handle reinitialization and lenient loading
@@ -199,9 +195,9 @@ public class CasIOUtils {
/**
* Loads a CAS from a URL source. The format is determined from the content.
- *
- * If the value of tsiUrl is non-null, it is read.
- * If values from both the tsiUrl and embedded values are available, the tsiUrl value is used.
+ * For SerialFormats ending with _TSI except for COMPRESSED_FILTERED_TSI,
+ * the CAS's type system and indexes definition are replaced.
+ * CasLoadMode is set according to the leniently flag.
*
* @param casUrl
* The url to deserialize the CAS from
@@ -220,8 +216,9 @@ public class CasIOUtils {
/**
* Loads a Cas from a URL source. The format is determined from the content.
- * For formats of type SERIALIZED_TSI, the type system and index definitions are reset.
- * Lenient is false; to use lenient loading, use the 4 argument form.
+ * For SerialFormats ending with _TSI except for COMPRESSED_FILTERED_TSI,
+ * the CAS's type system and indexes definition are replaced.
+ * CasLoadMode is DEFAULT.
*
* @param casInputStream
* The input stream containing the CAS. Caller should buffer this appropriately.
@@ -237,11 +234,14 @@ public class CasIOUtils {
/**
* Loads a CAS from an Input Stream. The format is determined from the content.
- * For formats of type SERIALIZED_TSI or COMPRESSED_FILTERED_TSI,
- * the type system and index definitions are read from the cas input source;
- * the value of tsiInputStream is ignored.
- * For other formats, if the tsiInputStream is not null,
- * type system and index definitions are read from that source.
+ *
+ * For SerialFormats ending with _TSI the embedded value is used instead of any supplied external TSI information.
+ * TSI information is available either via embedded value, or if a non-null input is passed for tsiInputStream.
+ *
+ * If TSI information is available, the CAS's type system and indexes definition are replaced,
+ * except for SerialFormats COMPRESSED_FILTERED, COMPRESSED_FILTERED_TS, and COMPRESSED_FILTERED_TSI.
+ *
+ * The CasLoadMode is DEFAULT.
*
* @param casInputStream -
* @param tsiInputStream -
@@ -253,31 +253,51 @@ public class CasIOUtils {
return load(casInputStream, tsiInputStream, aCAS, CasLoadMode.DEFAULT);
}
+ /**
+ * Loads a CAS from an Input Stream. The format is determined from the content.
+ *
+ * For SerialFormats ending with _TSI the embedded value is used instead of any supplied external TSI information.
+ * TSI information is available either via embedded value, or if a non-null input is passed for tsiInputStream.
+ *
+ * If TSI information is available, the CAS's type system and indexes definition are replaced,
+ * except for SerialFormats COMPRESSED_FILTERED, COMPRESSED_FILTERED_TS, and COMPRESSED_FILTERED_TSI.
+ *
+ * The CasLoadMode is set to LENIENT if the leniently flag is true; otherwise it is set to DEFAULT.
+ *
+ * @param casInputStream -
+ * @param tsiInputStream -
+ * @param aCAS -
+ * @return -
+ * @throws IOException -
+ */
public static SerialFormat load(InputStream casInputStream, InputStream tsiInputStream, CAS aCAS, boolean leniently) throws IOException {
return load(casInputStream, tsiInputStream, aCAS, leniently ? CasLoadMode.LENIENT : CasLoadMode.DEFAULT);
}
/**
- * Loads a CAS from a URL source. The format is determined from the content.
- * For formats of type SERIALIZED_TSI or COMPRESSED_FILTERED_TSI,
+ * Loads a CAS from an Input Stream. The format is determined from the content.
+ * For formats of ending in _TSI SERIALIZED_TSI or COMPRESSED_FILTERED_TSI,
* the type system and index definitions are read from the cas input source;
* the value of tsiInputStream is ignored.
+ *
* For other formats, if the tsiInputStream is not null,
* type system and index definitions are read from that source.
*
+ * If TSI information is available, the CAS's type system and indexes definition are replaced,
+ * except for SerialFormats COMPRESSED_FILTERED, COMPRESSED_FILTERED_TS, and COMPRESSED_FILTERED_TSI.
+ *
+ * If the CasLoadMode == REINIT, then the TSI information is also used for these 3 formats to replace the CAS's definitions.
+ *
* @param casInputStream
* The input stream containing the CAS, appropriately buffered.
* @param tsiInputStream
* The optional input stream containing the type system, appropriately buffered.
- * This is only used if the casInputStream does not already come
- * with an embedded CAS Type System and Index Definition, and is non-null.
+ * This is only used if it is non null and
+ * - the casInputStream does not already come with an embedded CAS Type System and Index Definition, or
+ * - the serial format is COMPRESSED_FILTERED_TSI
* @param aCAS
* The CAS that should be filled
* @param casLoadMode specifies loading alternative like lenient and reinit, see CasLoadMode.
- * For XCAS and XMI formats, ignore feature structures and features of non-existing types and/or features.
- * For Compressed Form 6, if true, the tsiInputStream is used only to supply the Type System for the serialized form;
- * the CAS type system is not altered.
- * For other formats, ignored.
* @return the SerialFormat of the loaded CAS
* @throws IOException
* - Problem loading from given InputStream
@@ -317,37 +337,11 @@ public class CasIOUtils {
******************************************/
Header h = CommonSerDes.readHeader(deserIn);
return casImpl.reinit(h, casInputStream, readCasManager(tsiInputStream), casLoadMode, null, AllowPreexistingFS.allow);
-// TypeSystemImpl ts = null;
-//
-//
-// if (h.isTypeSystemIncluded() || h.isTypeSystemIndexDefIncluded()) { // Load TS from CAS stream
-// try {
-// ObjectInputStream ois = new ObjectInputStream(deserIn);
-// embeddedCasMgrSerializer = (CASMgrSerializer) ois.readObject();
-// } catch (ClassNotFoundException e) {
-// /**Unrecognized serialized CAS format*/
-// throw new CASRuntimeException(CASRuntimeException.UNRECOGNIZED_SERIALIZED_CAS_FORMAT);
-// }
-// }
-//
-// maybeReinit(
-// (null == casMgrSerializer && h.isTypeSystemIndexDefIncluded())
-// ? embeddedCasMgrSerializer
-// : casMgrSerializer,
-// casLoadMode, casImpl);
-//
-// if (!h.isForm6() && casLoadMode == CasLoadMode.LENIENT) {
-// /**Lenient deserialization not support for input of type {0}.*/
-// throw new CASRuntimeException(CASRuntimeException.LENIENT_NOT_SUPPORTED, new Object[] {h.toString()});
-// }
-//
-// return casImpl.reinit(h, casInputStream, ts);
-
} else {
/******************************
- * Java Object Serialization
+ * Java Object loading
******************************/
ObjectInputStream ois = new ObjectInputStream(casInputStream);
try {
@@ -370,17 +364,6 @@ public class CasIOUtils {
}
}
}
-
-
-// private static CASMgrSerializer maybeGetExternalTSI(InputStream tsiInputStream, CASImpl casImpl) throws IOException {
-// return (tsiInputStream != null) ? readCasManager(tsiInputStream)
-// CASMgrSerializer casMgrSerializer = null;
-// if (tsiInputStream != null) {
-// casMgrSerializer = readCasManager(tsiInputStream);
-// casImpl.setupCasFromCasMgrSerializer(casMgrSerializer);
-// }
-// return casMgrSerializer;
-// }
/**
* Write the CAS in the specified format.
@@ -436,21 +419,24 @@ public class CasIOUtils {
case BINARY: // Java-serialized CAS without type system
serializeCAS(aCas, docOS);
break;
+ case BINARY_TSI: // Java-serialized CAS without type system
+ CASSerializer ser = new CASSerializer();
+ ser.addCAS((CASImpl) aCas, docOS, true);
+ 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)
+ new BinaryCasSerDes4((TypeSystemImpl)aCas.getTypeSystem(), false).serializeWithTsi((CASImpl) aCas, docOS);
+ break;
case COMPRESSED_FILTERED: // Binary compressed CAS (form 6)
serializeWithCompression(aCas, docOS, false, false);
break;
case COMPRESSED_FILTERED_TS:
- // Binary compressed CAS (form 6)
- // ... with embedded Java-serialized type system
serializeWithCompression(aCas, docOS, true, false);
typeSystemWritten = true; // Embedded type system
break;
case COMPRESSED_FILTERED_TSI:
- // Binary compressed CAS (form 6)
- // ... with embedded Java-serialized type system
serializeWithCompression(aCas, docOS, false, true);
typeSystemWritten = true; // Embedded type system
break;
@@ -464,10 +450,10 @@ public class CasIOUtils {
throw new IOException(e);
}
- // Write type system to the separate stream only if it has not alreay been embedded into the
+ // Write type system to the separate stream only if it has not already been embedded into the
// main stream
if (tsiOS != null && !typeSystemWritten) {
- writeTypeSystem(aCas, tsiOS);
+ writeTypeSystem(aCas, tsiOS, true);
}
}
@@ -482,21 +468,18 @@ public class CasIOUtils {
throw new IOException(e);
}
}
-
-// private static void maybeReinit(CASMgrSerializer casMgrSerializer, CasLoadMode casLoadMode, CASImpl cas) {
-// if (casLoadMode == CasLoadMode.REINIT && casMgrSerializer != null) {
-// cas.setupCasFromCasMgrSerializer(casMgrSerializer);
-// }
-// }
-
+
private static void writeJavaObject(Object o, OutputStream aOS) throws IOException {
ObjectOutputStream tsiOS = new ObjectOutputStream(aOS);
tsiOS.writeObject(o);
tsiOS.flush();
}
- private static void writeTypeSystem(CAS aCas, OutputStream aOS) throws IOException {
- writeJavaObject(serializeCASMgr((CASImpl) aCas), aOS);
+ public static void writeTypeSystem(CAS aCas, OutputStream aOS, boolean includeIndexDefs) throws IOException {
+ writeJavaObject(includeIndexDefs
+ ? Serialization.serializeCASMgr((CASImpl) aCas)
+ : Serialization.serializeCASMgrTypeSystemOnly((CASImpl) aCas)
+ , aOS);
}
private static void closeQuitely(Closeable closeable) {
Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java?rev=1756689&r1=1756688&r2=1756689&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/util/CasIOUtilsTest.java Wed Aug 17 20:54:21 2016
@@ -157,11 +157,19 @@ public class CasIOUtilsTest extends Test
public void testS0() throws Exception {
testFormat(SerialFormat.BINARY, "bins0", false);
}
-
+
+ public void testS0tsi() throws Exception {
+ testFormat(SerialFormat.BINARY_TSI, "bins0", false);
+ }
+
public void testS4() throws Exception {
testFormat(SerialFormat.COMPRESSED, "bins4", false);
}
+ public void testS4tsi() throws Exception {
+ testFormat(SerialFormat.COMPRESSED_TSI, "bins4", false);
+ }
+
public void testS6() throws Exception {
testFormat(SerialFormat.COMPRESSED_FILTERED, "bins6", false);
}