private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException { File outFile = new File(outputDirectory, fileName + ".xcas"); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
/** * Write the CAS data to a SAX content handler. * * @param cas * The CAS to be serialized. * @param contentHandler * The SAX content handler the data is written to. * @throws IOException passed thru * @throws SAXException passed thru */ public void serialize(CAS cas, ContentHandler contentHandler) throws IOException, SAXException { serialize(cas, contentHandler, true); }
/** * Convert CAS Container (aka CAS Object) to CAS Data * * @param aContainer * CAS to convert * * @return CasData object containing all information from the CAS */ public CasData casContainerToCasData(CAS aContainer) { // generate XCAS events and pipe them to XCasToCasDataSaxHandler CasData result = new CasDataImpl(); XCasToCasDataSaxHandler handler = new XCasToCasDataSaxHandler(result); XCASSerializer xcasSer = new XCASSerializer(aContainer.getTypeSystem()); xcasSer.setDocumentTypeName(this.getDocumentTextTypeName()); xcasSer.setDocumentTextFeature(this.getDocumentTextFeatureName()); try { xcasSer.serialize(aContainer, handler); } catch (IOException e) { throw new UIMARuntimeException(e); } catch (SAXException e) { throw new UIMARuntimeException(e); } return result; } }
/** * Serializes an XCAS to a stream. * * @param aCAS * CAS to serialize. * @param aStream * output stream to which to write the XCAS XML document * * @throws SAXException * if a problem occurs during XCAS serialization * @throws IOException * if an I/O failure occurs */ public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException, IOException { XCASSerializer.serialize(aCAS, aStream, false); }
try { UIMAFramework.getLogger().log(Level.FINEST, "Serializing CAS."); XCASSerializer xcasSerializer = new XCASSerializer(myCas.getTypeSystem(), this.uimaContext); xcasSerializer.setDocumentTypeName(Constants.VINCI_DETAG); xcasSerializer.setDocumentTextFeature(null); XTalkSerializer s = new XTalkSerializer(os, xcasSerializer); try { xcasSerializer.serialize(myCas, s, includeDocText, outOfTypeSystemData); } catch (org.xml.sax.SAXException e) {
private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException { File outFile = new File(outputDirectory, fileName + ".xcas"); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }
/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@link OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }
/** * Returns XML (XCAS) representation of this CAS, stripped of all newlines. */ @Override public String toString() { if (cas == null) return "null"; // Use StringWriter instead of OutputStream for XMLSerializer so that // we don't need to worry about string encoding (utf-8 vs. utf-16, etc.) StringWriter writer = new StringWriter(); XMLSerializer xmlSerializer = new XMLSerializer(writer); XCASSerializer casSerializer = new XCASSerializer(cas.getTypeSystem()); try { casSerializer.serialize(cas, xmlSerializer.getContentHandler()); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String xml = writer.toString(); xml = xml.replace("\n", ""); return xml; }
/** * Write the CAS data to a SAX content handler. * * @param cas * The CAS to be serialized. * @param contentHandler * The SAX content handler the data is written to. * @param encodeDoc * If set to false, no uima.tcas.Document structure will be created, and the document * text will not be serialized. * @throws IOException passed thru * @throws SAXException passed thru */ public void serialize(CAS cas, ContentHandler contentHandler, boolean encodeDoc) throws IOException, SAXException { serialize(cas, contentHandler, encodeDoc, null); }
/** * Serialize a CAS to a file in XCAS format * * @param aCas * CAS to serialize * @param name * output file * * @throws IOException * if an I/O failure occurs * @throws SAXException * if an error occurs generating the XML text */ private void writeXCas(CAS aCas, File name) throws IOException, SAXException { FileOutputStream out = null; try { out = new FileOutputStream(name); XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem()); XMLSerializer sax2xml = new XMLSerializer(out, false); ser.serialize(aCas, sax2xml.getContentHandler()); } finally { if (out != null) { out.close(); } } }
/** * * @param aCas * the source CAS * @param aFile * the file to write to * @throws IOException * if there is a problem writing the file * @deprecated Use {@link CasIOUtils#save(CAS, OutputStream, org.apache.uima.cas.SerialFormat)} * with {@link SerialFormat#XCAS} instead. */ @Deprecated public static void writeXCas(CAS aCas, File aFile) throws IOException { OutputStream os = null; try { os = new FileOutputStream(aFile); XCASSerializer.serialize(aCas, os); } catch (SAXException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; // NOPMD // If we were using Java 1.6 and add the wrapped exception to the IOException // constructor, we would not get a warning here } finally { closeQuietly(os); } }
/** * Serializes an XCAS to a stream. * * @param aCAS * CAS to serialize. * @param aStream * output stream to which to write the XCAS XML document * @param isFormattedOutput * if true the XCAS will be serialized formatted * * @throws SAXException * if a problem occurs during XCAS serialization * @throws IOException * if an I/O failure occurs */ public static void serialize(CAS aCAS, OutputStream aStream, boolean isFormattedOutput) throws SAXException, IOException { XCASSerializer xcasSerializer = new XCASSerializer(aCAS.getTypeSystem()); XMLSerializer sax2xml = new XMLSerializer(aStream, isFormattedOutput); xcasSerializer.serialize(aCAS, sax2xml.getContentHandler()); }
outputFile = new File( iv_outputDir + File.separatorChar + docName ); out = new FileOutputStream( outputFile ); XCASSerializer.serialize( view.getCas(), out, true ); // true -> formats the output } finally { iv_procCount++;
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xcasFile)); XMLSerializer xmlSerializer = new XMLSerializer(outStream); XCASSerializer xcasSerializer = new XCASSerializer(this.main.getCas().getTypeSystem()); xcasSerializer.serialize(this.main.getCas(), xmlSerializer.getContentHandler()); outStream.close(); } catch (IOException e) {
outputFile = new File( iv_outputDir + File.separatorChar + docName ); out = new FileOutputStream( outputFile ); XCASSerializer.serialize( view.getCas(), out, true ); // true -> formats the output } finally { iv_procCount++;
XMLSerializer xmlSer = new XMLSerializer(outStream, false); if (mXCAS.equalsIgnoreCase("xcas")) { XCASSerializer ser = new XCASSerializer(aCAS.getTypeSystem()); ser.serialize(aCAS, xmlSer.getContentHandler());
XCASSerializer.serialize(aJCas.getCas(), byteArrayOutputStream); this.writer.append(new Text(relativeDocumentPath), new Text(byteArrayOutputStream.toString("UTF-8")));
/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@link OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }
break; case XCAS: XCASSerializer.serialize(aCas, docOS, true); // true = formatted output break; case SERIALIZED:
/** * Serializes a CAS in the given format. * * @param jcas * CAS (Common Analysis System) to be serialized. * @param type * type of cTAKES (UIMA) serializer used to write CAS. * @param prettyPrint * {@code true} to do pretty printing of output. * @param stream * {@see OutputStream} object used to print out information * extracted by using cTAKES. * @throws SAXException * if there was a SAX exception. * @throws IOException * if any I/O error occurs. */ public static void serialize(JCas jcas, CTAKESSerializer type, boolean prettyPrint, OutputStream stream) throws SAXException, IOException { if (type == CTAKESSerializer.XCAS) { XCASSerializer.serialize(jcas.getCas(), stream, prettyPrint); } else if (type == CTAKESSerializer.XMI) { XmiCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream, prettyPrint, new XmiSerializationSharedData()); } else { XmlCasSerializer.serialize(jcas.getCas(), jcas.getTypeSystem(), stream); } }