@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }
/** * 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 SAXException if there was a SAX exception */ public void serialize(CAS cas, ContentHandler contentHandler) throws SAXException { this.serialize(cas, contentHandler, (ErrorHandler) null); }
/** * Serializes a CAS to an XMI stream. * * @param aCAS * CAS to serialize. * @param aStream * output stream to which to write the XMI document * * @throws SAXException * if a problem occurs during XMI serialization */ public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException { serialize(aCAS, null, aStream, false, null); }
private static void writeXmi(CAS aCas, File name) throws IOException, SAXException { FileOutputStream out = null; try { // write XMI out = new FileOutputStream(name); XmiCasSerializer ser = new XmiCasSerializer(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. * @param errorHandler the SAX Error Handler to use * * @throws SAXException if there was a SAX exception */ public void serialize(CAS cas, ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException { serialize(cas, contentHandler, errorHandler, null, null); }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }
/** * Serializes a CAS to XMI format and writes it to an output stream. * * @param aCAS * CAS to serialize. * @param aStream * output stream to which to write the XMI document * * @throws SAXException * if a problem occurs during XMI serialization * @throws IOException * if an I/O failure occurs */ public static void serialize(CAS aCAS, OutputStream aStream) throws SAXException, IOException { XmiCasSerializer.serialize(aCAS, aStream); }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(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); } }
public String serializeCasToXmi(CAS aCAS, XmiSerializationSharedData serSharedData, Marker aMarker) throws Exception { Writer writer = new StringWriter(); try { XMLSerializer xmlSer = new XMLSerializer(writer, false); XmiCasSerializer ser = new XmiCasSerializer(aCAS.getTypeSystem()); ser.serialize(aCAS, xmlSer.getContentHandler(), null, serSharedData, aMarker); return writer.toString(); } catch (SAXException e) { throw e; } finally { writer.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. * @param sharedData * data structure used to allow the XmiCasSerializer and XmiCasDeserializer to share * information. * @param errorHandler the SAX Error Handler to use * * @throws SAXException if there was a SAX exception */ public void serialize(CAS cas, ContentHandler contentHandler, ErrorHandler errorHandler, XmiSerializationSharedData sharedData) throws SAXException { serialize(cas, contentHandler, errorHandler, sharedData, null); }
private void writeXmi(CAS aCas, OutputStream out) throws IOException, SAXException { // seems like it is not necessary to buffer outputStream for SAX TransformationHandler // out = new BufferedOutputStream(out); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, xmlFormatted); ser.serialize(aCas, xmlSer.getContentHandler()); } }
/** * Serializes a CAS to an XMI stream. Allows a TypeSystem to be specified, to which the produced * XMI will conform. Any types or features not in the target type system will not be serialized. * * @param aCAS * CAS to serialize. * @param aTargetTypeSystem * type system to which the produced XMI will conform. Any types or features not in the * target type system will not be serialized. A null value indicates that all types and features * will be serialized. * @param aStream * output stream to which to write the XMI document * * @throws SAXException * if a problem occurs during XMI serialization */ public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, OutputStream aStream) throws SAXException { serialize(aCAS, aTargetTypeSystem, aStream, false, null); }
@Override public void write(OutputStream aStream) throws Exception { XmiCasSerializer ser = new XmiCasSerializer(cas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(aStream, false); ser.serialize(cas, xmlSer.getContentHandler()); }
/** * Serializes a CAS to XMI format and writes it to an output stream. Allows a TypeSystem to be * specified, to which the produced XMI will conform. Any types or features not in the target type * system will not be serialized. * * @param aCAS * CAS to serialize. * @param aTargetTypeSystem * type system to which the produced XMI will conform. Any types or features not in the * target type system will not be serialized. * * @param aStream * output stream to which to write the XMI document * * @throws SAXException * if a problem occurs during XMI serialization * @throws IOException * if an I/O failure occurs */ public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, OutputStream aStream) throws SAXException, IOException { XmiCasSerializer.serialize(aCAS, aTargetTypeSystem, aStream); } }
/** * Serialize a CAS to a file in XMI format * * @param cas CAS to serialize * @param file output file * @throws IOException - * @throws SAXException - */ static private void writeXmi( final CAS cas, final File file ) throws IOException, SAXException { try ( OutputStream outputStream = new BufferedOutputStream( new FileOutputStream( file ) ) ) { XmiCasSerializer casSerializer = new XmiCasSerializer( cas.getTypeSystem() ); XMISerializer xmiSerializer = new XMISerializer( outputStream ); casSerializer.serialize( cas, xmiSerializer.getContentHandler() ); } }
/** * Serializes a CAS to an XMI stream. This version of this method allows many options to be configured. * * @param aCAS * CAS to serialize. * @param aTargetTypeSystem * type system to which the produced XMI will conform. Any types or features not in the * target type system will not be serialized. A null value indicates that all types and features * will be serialized. * @param aStream * output stream to which to write the XMI document * @param aPrettyPrint * if true the XML output will be formatted with newlines and indenting. If false it will be unformatted. * @param aSharedData * an optional container for data that is shared between the {@link XmiCasSerializer} and the {@link XmiCasDeserializer}. * See the JavaDocs for {@link XmiSerializationSharedData} for details. * * @throws SAXException * if a problem occurs during XMI serialization */ public static void serialize(CAS aCAS, TypeSystem aTargetTypeSystem, OutputStream aStream, boolean aPrettyPrint, XmiSerializationSharedData aSharedData) throws SAXException { serialize(aCAS, aTargetTypeSystem, aStream, aPrettyPrint, aSharedData, null); }
private String serializeCas(CAS aCas) throws RecommendationException { try (StringWriter out = new StringWriter()) { // Passing "null" as the type system to the XmiCasSerializer means that we want // to serialize all types (i.e. no filtering for a specific target type system). XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(null); XMLSerializer sax2xml = new XMLSerializer(out, true); xmiCasSerializer.serialize(aCas, sax2xml.getContentHandler(), null, null, null); return out.toString(); } catch (CASRuntimeException | SAXException | IOException e) { throw new RecommendationException("Error while serializing CAS!", e); } }
/** * * @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#XMI} instead. */ @Deprecated public static void writeXmi(CAS aCas, File aFile) throws IOException { OutputStream os = null; try { os = new FileOutputStream(aFile); XmiCasSerializer.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); } }
private void writeXmi(CAS aCas, String id) throws IOException, SAXException { File outFile = new File(outputDirectory, id ); FileOutputStream out = null; try { out = new FileOutputStream(outFile); XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem()); XMLSerializer xmlSer = new XMLSerializer(out, false); ser.serialize(aCas, xmlSer.getContentHandler()); } finally { if (out != null) { out.close(); } } }