intArrayFS.set(4, 5);
cas.getIndexRepository().addFS(intArrayFS);
// serialize the CAS
StringWriter sw = new StringWriter();
XMLSerializer xmlSer = new XMLSerializer(sw, false);
XmiCasSerializer xmiSer = new XmiCasSerializer(cas.getTypeSystem());
xmiSer.serialize(cas, xmlSer.getContentHandler());
String xml = sw.getBuffer().toString();
// deserialize into another CAS
CAS cas2 = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(),
new FsIndexDescription[0]);
XmiCasDeserializer deser2 = new XmiCasDeserializer(cas2.getTypeSystem());
ContentHandler deserHandler2 = deser2.getXmiCasHandler(cas2);
SAXParserFactory fact = SAXParserFactory.newInstance();
SAXParser parser = fact.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
xmlReader.setContentHandler(deserHandler2);
xmlReader.parse(new InputSource(new StringReader(xml)));
//test that index is correctly populated
Type intArrayType = cas2.getTypeSystem().getType(CAS.TYPE_NAME_INTEGER_ARRAY);
Iterator iter = cas2.getIndexRepository().getAllIndexedFS(intArrayType);
assertTrue(iter.hasNext());
IntArrayFS intArrayFS2 = (IntArrayFS)iter.next();
assertFalse(iter.hasNext());
assertEquals(5, intArrayFS2.size());
assertEquals(1, intArrayFS2.get(0));
assertEquals(2, intArrayFS2.get(1));
assertEquals(3, intArrayFS2.get(2));
assertEquals(4, intArrayFS2.get(3));
assertEquals(5, intArrayFS2.get(4));
// test that serializing the new CAS produces the same XML
sw = new StringWriter();
xmlSer = new XMLSerializer(sw, false);
xmiSer = new XmiCasSerializer(cas2.getTypeSystem());
xmiSer.serialize(cas2, xmlSer.getContentHandler());
String xml2 = sw.getBuffer().toString();
assertTrue(xml2.equals(xml));
}