Author: schor Date: Tue May 7 12:54:24 2013 New Revision: 1479887 URL: http://svn.apache.org/r1479887 Log: [UIMA-2874] Make uniform method for doing both forms of compressed serialization and add to the CAS and CASImpl interface/class. Remove methods not usable from BinaryCasSerDes6 (can't do delta things without ReuseInfo)
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.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/test/java/org/apache/uima/cas/impl/SerDesTest6.java Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java?rev=1479887&r1=1479886&r2=1479887&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java (original) +++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/CAS.java Tue May 7 12:54:24 2013 @@ -19,13 +19,19 @@ package org.apache.uima.cas; +import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import org.apache.uima.cas.admin.CASAdminException; +import org.apache.uima.cas.impl.BinaryCasSerDes4; +import org.apache.uima.cas.impl.BinaryCasSerDes6; import org.apache.uima.cas.impl.LowLevelCAS; +import org.apache.uima.cas.impl.MarkerImpl; +import org.apache.uima.cas.impl.TypeSystemImpl; +import org.apache.uima.cas.impl.BinaryCasSerDes6.ReuseInfo; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.cas.text.AnnotationIndex; import org.apache.uima.jcas.JCas; @@ -1056,4 +1062,38 @@ public interface CAS extends AbstractCas */ List<Marker> getMarkers(); + /** + * Serialize in compressed binary form 4 + * @param out - an OutputStream, a DataOutputStream, or a File + * @throws IOException + */ + public void serializeWithCompression(Object out) throws IOException ; + + /** + * Serialize in compress binary form 4, only the delta part of a CAS + * @param out - an OutputStream, a DataOutputStream, or a File + * @param marker identifying where the delta starts + * @throws IOException + */ + public void serializeWithCompression(Object out, Marker marker) throws IOException; + + /** + * Serialize in compressed binary form 6 + * @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) + * @throws IOException + */ + public ReuseInfo serializeWithCompression(Object out, TypeSystem tgtTypeSystem) throws IOException; + + /** + * @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 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 service did the original deserialization of the CAS now being serialized as a delta CAS + * @throws IOException + */ + public void serializeWithCompression(Object out, TypeSystem tgtTypeSystem, Marker mark, ReuseInfo reuseInfo) throws IOException; + } 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=1479887&r1=1479886&r2=1479887&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 Tue May 7 12:54:24 2013 @@ -520,7 +520,7 @@ public class BinaryCasSerDes6 { } /** - * Setup to serialize (not delta) or deserialize (not delta) using binary compression, no type mapping and only processing reachable Feature Structures + * Setup to serialize (not delta) or deserialize (not delta) using binary compression, no type mapping but only processing reachable Feature Structures * @param cas */ public BinaryCasSerDes6(AbstractCas cas) { @@ -528,22 +528,13 @@ public class BinaryCasSerDes6 { } /** - * Setup to serialize (maybe delta) or deserialize (not delta) using binary compression, no type mapping and only processing reachable Feature Structures - * @param cas - * @param mark - */ - public BinaryCasSerDes6(AbstractCas cas, MarkerImpl mark) { - this(cas, mark, null, null, false, CompressLevel.Default, CompressStrat.Default); - } - - /** - * Setup to serialize (maybe delta) or deserialize (not delta) using binary compression, with type mapping and only processing reachable Feature Structures + * Setup to serialize (not delta) or deserialize (not delta) using binary compression, with type mapping and only processing reachable Feature Structures * @param cas * @param mark * @param tgtTs */ - public BinaryCasSerDes6(AbstractCas cas, MarkerImpl mark, TypeSystemImpl tgtTs) { - this(cas, mark, tgtTs, null, false, CompressLevel.Default, CompressStrat.Default); + public BinaryCasSerDes6(AbstractCas cas, TypeSystemImpl tgtTs) { + this(cas, null, tgtTs, null, false, CompressLevel.Default, CompressStrat.Default); } /** @@ -551,7 +542,7 @@ public class BinaryCasSerDes6 { * @param cas * @param mark * @param tgtTs - * @param rfs Reused Feature Structure information - speed up on serialization, required on delta deserialization + * @param rfs Reused Feature Structure information - required for both delta serialization and delta deserialization */ public BinaryCasSerDes6(AbstractCas cas, MarkerImpl mark, TypeSystemImpl tgtTs, ReuseInfo rfs) { this(cas, mark, tgtTs, rfs, false, CompressLevel.Default, CompressStrat.Default); 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=1479887&r1=1479886&r2=1479887&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 Tue May 7 12:54:24 2013 @@ -20,7 +20,6 @@ package org.apache.uima.cas.impl; import java.io.ByteArrayInputStream; -import java.io.DataInput; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; @@ -2514,11 +2513,7 @@ public class CASImpl extends AbstractCas @Deprecated public JCas getJCas(SofaID aSofaID) throws CASException { SofaFS sofa = getSofa(aSofaID); - if (sofa == null) { - CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_NOT_FOUND, - new String[] { aSofaID.getSofaID() }); - throw e; - } + // sofa guaranteed to be non-null by above method. return getJCas(sofa); } @@ -2575,11 +2570,7 @@ public class CASImpl extends AbstractCas } // get Sofa and switch to view SofaFS sofa = getSofa(absoluteSofaName); - if (sofa == null) { - CASRuntimeException e = new CASRuntimeException(CASRuntimeException.SOFANAME_NOT_FOUND, - new String[] { absoluteSofaName }); - throw e; - } + // sofa guaranteed to be non-null by above method return getView(sofa); } @@ -4313,12 +4304,34 @@ public class CASImpl extends AbstractCas } /** - * Serialize in compressed binary form - * @param out - an OutputStream, a DataOutputStream, or a File - * @throws IOException + * @see org.apache.uima.cas.CAS#serializeWithCompression(Object out) */ public void serializeWithCompression(Object out) throws IOException { (new BinaryCasSerDes4(this.getTypeSystemImpl(), false)).serialize(this, out); } + /** + * @see org.apache.uima.cas.CAS#serializeWithCompression(Object out, Marker marker) + */ + public void serializeWithCompression(Object out, Marker marker) throws IOException { + (new BinaryCasSerDes4(this.getTypeSystemImpl(), false)).serialize(this, out, marker); + } + + /** + * @see org.apache.uima.cas.CAS#serializeWithCompression(Object out, TypeSystem tgtTypeSystem, Marker marker) + */ + public ReuseInfo serializeWithCompression(Object out, TypeSystem tgtTypeSystem) throws IOException { + BinaryCasSerDes6 bcs = new BinaryCasSerDes6(this, (TypeSystemImpl) tgtTypeSystem); + bcs.serialize(out); + return bcs.getReuseInfo(); + } + + /** + * @see org.apache.uima.cas.CAS#serializeWithCompression(Object out, TypeSystem tgtTypeSystem, Marker mark, ReuseInfo reuseInfo) + */ + public void serializeWithCompression(Object out, TypeSystem tgtTypeSystem, Marker mark, ReuseInfo reuseInfo) throws IOException { + BinaryCasSerDes6 bcs = new BinaryCasSerDes6(this, (MarkerImpl) mark, (TypeSystemImpl) tgtTypeSystem, reuseInfo); + bcs.serialize(out); + } + } Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java?rev=1479887&r1=1479886&r2=1479887&view=diff ============================================================================== --- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java (original) +++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/SerDesTest6.java Tue May 7 12:54:24 2013 @@ -1120,7 +1120,7 @@ public class SerDesTest6 extends TestCas if (doPlain) { (new CASSerializer()).addCAS(casSrc, baos); } else { - bcs = new BinaryCasSerDes6(casSrc, null, casTgt.getTypeSystemImpl()); + bcs = new BinaryCasSerDes6(casSrc, casTgt.getTypeSystemImpl()); SerializationMeasures sm = bcs.serialize(baos); if (null != sm) { System.out.println(sm); @@ -1151,10 +1151,10 @@ public class SerDesTest6 extends TestCas bcs.serialize(baos); } ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - bcs = new BinaryCasSerDes6(casTgt, null, casSrc.getTypeSystemImpl()); + bcs = new BinaryCasSerDes6(casTgt, casSrc.getTypeSystemImpl()); bcs.deserialize(bais); - bcs = new BinaryCasSerDes6(casSrc, null, casTgt.getTypeSystemImpl()); + bcs = new BinaryCasSerDes6(casSrc, casTgt.getTypeSystemImpl()); assertTrue(bcs.compareCASes(casSrc, casTgt)); } catch (IOException e) { throw new RuntimeException(e); @@ -1178,7 +1178,7 @@ public class SerDesTest6 extends TestCas Serialization.serializeCAS(casSrc, baos, mark); } } else { - BinaryCasSerDes6 bcs = new BinaryCasSerDes6(casSrc, mark, casTgt.getTypeSystemImpl()); + BinaryCasSerDes6 bcs = new BinaryCasSerDes6(casSrc, casTgt.getTypeSystemImpl()); SerializationMeasures sm = bcs.serialize(baos); if (sm != null) {System.out.println(sm);} riToReturn[0] = bcs.getReuseInfo();