Author: schor
Date: Wed Aug 24 14:44:37 2016
New Revision: 1757533
URL: http://svn.apache.org/viewvc?rev=1757533&view=rev
Log:
[UIMA-4685] add load method with passed in type system for form 6
Modified:
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/util/CasIOUtils.java
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=1757533&r1=1757532&r2=1757533&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 24 14:44:37 2016
@@ -1706,7 +1706,7 @@ public class BinaryCasSerDes6 {
cas.resetNoQuestions();
}
- cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this,
AllowPreexistingFS.allow);
+ cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this,
AllowPreexistingFS.allow, null);
// deserializeAfterVersion(deserIn, isReadingDelta,
AllowPreexistingFS.allow);
}
@@ -1727,7 +1727,7 @@ public class BinaryCasSerDes6 {
throw new UnsupportedOperationException("Delta CAS required for this
call");
}
- cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this,
allowPreexistingFS);
+ cas.reinit(h, deserIn, null, CasLoadMode.DEFAULT, this,
allowPreexistingFS, null);
}
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=1757533&r1=1757532&r2=1757533&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 24 14:44:37 2016
@@ -1390,7 +1390,7 @@ public class CASImpl extends AbstractCas
try {
Header h = CommonSerDes.readHeader(dis);
- return reinit(h, istream, null, CasLoadMode.DEFAULT, null,
AllowPreexistingFS.allow);
+ return reinit(h, istream, null, CasLoadMode.DEFAULT, null,
AllowPreexistingFS.allow, null);
} catch (IOException e) {
String msg = e.getMessage();
if (msg == null) {
@@ -1431,9 +1431,10 @@ public class CASImpl extends AbstractCas
CASMgrSerializer casMgrSerializer,
CasLoadMode casLoadMode,
BinaryCasSerDes6 f6,
- AllowPreexistingFS allowPreexistingFS) throws
CASRuntimeException {
+ AllowPreexistingFS allowPreexistingFS,
+ TypeSystemImpl ts) throws CASRuntimeException {
if (this != this.svd.baseCAS) {
- return this.svd.baseCAS.reinit(h, istream, casMgrSerializer,
casLoadMode, f6, allowPreexistingFS);
+ return this.svd.baseCAS.reinit(h, istream, casMgrSerializer,
casLoadMode, f6, allowPreexistingFS, ts);
}
final DataInputStream dis =
CommonSerDes.maybeWrapToDataInputStream(istream);
@@ -1473,10 +1474,18 @@ public class CASImpl extends AbstractCas
tsRead.commit(); // no generators set up
}
+ TypeSystemImpl ts_for_decoding = (ts != null)
+ ? ts
+ : (f6 == null)
+ ? tsRead
+ : (f6.getTgtTs() == null)
+ ? tsRead
+ : f6.getTgtTs();
+
try {
BinaryCasSerDes6 bcsd = (f6 != null)
- ? new BinaryCasSerDes6(f6, (f6.getTgtTs()
== null) ? tsRead : f6.getTgtTs())
- : new BinaryCasSerDes6(this, tsRead);
+ ? new BinaryCasSerDes6(f6, ts_for_decoding)
+ : new BinaryCasSerDes6(this,
ts_for_decoding);
bcsd.deserializeAfterVersion(dis, delta, AllowPreexistingFS.allow);
return h.typeSystemIndexDefIncluded
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=1757533&r1=1757532&r2=1757533&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 24 14:44:37 2016
@@ -36,6 +36,7 @@ import org.apache.uima.UIMARuntimeExcept
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.SerialFormat;
+import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.admin.CASMgr;
import org.apache.uima.cas.impl.AllowPreexistingFS;
import org.apache.uima.cas.impl.BinaryCasSerDes4;
@@ -306,6 +307,29 @@ public class CasIOUtils {
*/
public static SerialFormat load(InputStream casInputStream, InputStream
tsiInputStream, CAS aCAS,
CasLoadMode casLoadMode) throws IOException {
+ return load(casInputStream, tsiInputStream, aCAS, casLoadMode, null);
+ }
+
+ /**
+ * This is used for loading Form 6 compressed CASes where the type system to
use to deserialize is provided as an argument.
+ *
+ * @param casInputStream
+ * The input stream containing the CAS, appropriately buffered.
+ * @param aCAS
+ * The CAS that should be filled
+ * @param typeSystem the type system to use for decoding the serialized
form, must be non-null
+ * @return the SerialFormat of the loaded CAS
+ * @throws IOException Problem loading from given InputStream
+ */
+ public static SerialFormat load(InputStream casInputStream, CAS aCAS,
TypeSystem typeSystem) throws IOException {
+ if (null == typeSystem) {
+ throw new IllegalArgumentException("typeSystem argument cannot be null");
+ }
+ return load(casInputStream, null, aCAS, CasLoadMode.DEFAULT,
(TypeSystemImpl) typeSystem);
+ }
+
+ private static SerialFormat load(InputStream casInputStream, InputStream
tsiInputStream, CAS aCAS,
+ CasLoadMode casLoadMode, TypeSystemImpl typeSystem) throws IOException {
if (!casInputStream.markSupported()) {
casInputStream = new BufferedInputStream(casInputStream);
@@ -338,7 +362,7 @@ public class CasIOUtils {
* Binary, Compressed Binary (form 4 or 6)
******************************************/
Header h = CommonSerDes.readHeader(deserIn);
- return casImpl.reinit(h, casInputStream, readCasManager(tsiInputStream),
casLoadMode, null, AllowPreexistingFS.allow);
+ return casImpl.reinit(h, casInputStream, readCasManager(tsiInputStream),
casLoadMode, null, AllowPreexistingFS.allow, typeSystem);
} else {