List of usage examples for javax.xml.stream XMLStreamWriter writeStartDocument
public void writeStartDocument(String encoding, String version) throws XMLStreamException;
From source file:XmlReaderToWriter.java
public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException { switch (xmlr.getEventType()) { case XMLEvent.START_ELEMENT: final String localName = xmlr.getLocalName(); final String namespaceURI = xmlr.getNamespaceURI(); if (namespaceURI != null && namespaceURI.length() > 0) { final String prefix = xmlr.getPrefix(); if (prefix != null) writer.writeStartElement(prefix, localName, namespaceURI); else/*from w w w . j a v a 2 s .co m*/ writer.writeStartElement(namespaceURI, localName); } else { writer.writeStartElement(localName); } for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) { writer.writeNamespace(xmlr.getNamespacePrefix(i), xmlr.getNamespaceURI(i)); } for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) { String attUri = xmlr.getAttributeNamespace(i); if (attUri != null) writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); else writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; case XMLEvent.SPACE: case XMLEvent.CHARACTERS: writer.writeCharacters(xmlr.getTextCharacters(), xmlr.getTextStart(), xmlr.getTextLength()); break; case XMLEvent.PROCESSING_INSTRUCTION: writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData()); break; case XMLEvent.CDATA: writer.writeCData(xmlr.getText()); break; case XMLEvent.COMMENT: writer.writeComment(xmlr.getText()); break; case XMLEvent.ENTITY_REFERENCE: writer.writeEntityRef(xmlr.getLocalName()); break; case XMLEvent.START_DOCUMENT: String encoding = xmlr.getCharacterEncodingScheme(); String version = xmlr.getVersion(); if (encoding != null && version != null) writer.writeStartDocument(encoding, version); else if (version != null) writer.writeStartDocument(xmlr.getVersion()); break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.DTD: writer.writeDTD(xmlr.getText()); break; } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * This method creates the XMI file. Created content is:<br/> * <code><?xml version="{@link XMIConstants4SchemaGraph2XMI#XML_VERSION}" encoding="{@link XMIConstants4SchemaGraph2XMI#XML_ENCODING}"?><br/> * <!-- content created by {@link SchemaGraph2XMI#createRootElement(XMLStreamWriter, SchemaGraph)} --> * </code>/*from w w w . j a v a2 s .c o m*/ * * @param xmiName * {@link String} the path of the XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException * @throws IOException */ private void createXMI(String xmiName, SchemaGraph schemaGraph) throws XMLStreamException, IOException { Writer out = null; XMLStreamWriter writer = null; try { // create the XMLStreamWriter which creates the current xmi-file. out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmiName), "UTF-8")); XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); writer = factory.createXMLStreamWriter(out); // write the first line writer.writeStartDocument(XMIConstants4SchemaGraph2XMI.XML_ENCODING, XMIConstants4SchemaGraph2XMI.XML_VERSION); createRootElement(writer, schemaGraph); // write the end of the document writer.writeEndDocument(); // close the XMLStreamWriter writer.flush(); out.flush(); } catch (Exception e) { e.printStackTrace(); } finally { // no handling of exceptions, because they are throw as mentioned in // the declaration. if (writer != null) { writer.close(); } if (out != null) { out.close(); } } }
From source file:Main.java
/** * Borrowed from org.apache.xml.security.test.stax.utils.XmlReaderToWriter *//* ww w . jav a 2 s . c o m*/ public static void write(XMLStreamReader xmlr, XMLStreamWriter writer) throws XMLStreamException { switch (xmlr.getEventType()) { case XMLEvent.START_ELEMENT: final String localName = xmlr.getLocalName(); final String namespaceURI = xmlr.getNamespaceURI(); if (namespaceURI != null && namespaceURI.length() > 0) { final String prefix = xmlr.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, localName, namespaceURI); } else { writer.writeStartElement(namespaceURI, localName); } } else { writer.writeStartElement(localName); } for (int i = 0, len = xmlr.getNamespaceCount(); i < len; i++) { String prefix = xmlr.getNamespacePrefix(i); if (prefix == null) { writer.writeDefaultNamespace(xmlr.getNamespaceURI(i)); } else { writer.writeNamespace(prefix, xmlr.getNamespaceURI(i)); } } for (int i = 0, len = xmlr.getAttributeCount(); i < len; i++) { final String attUri = xmlr.getAttributeNamespace(i); if (attUri != null && attUri.length() > 0) { final String prefix = xmlr.getAttributePrefix(i); if (prefix != null) { writer.writeAttribute(prefix, attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } else { writer.writeAttribute(attUri, xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } } else { writer.writeAttribute(xmlr.getAttributeLocalName(i), xmlr.getAttributeValue(i)); } } break; case XMLEvent.END_ELEMENT: writer.writeEndElement(); break; case XMLEvent.SPACE: case XMLEvent.CHARACTERS: char[] text = new char[xmlr.getTextLength()]; xmlr.getTextCharacters(0, text, 0, xmlr.getTextLength()); writer.writeCharacters(text, 0, text.length); break; case XMLEvent.PROCESSING_INSTRUCTION: writer.writeProcessingInstruction(xmlr.getPITarget(), xmlr.getPIData()); break; case XMLEvent.CDATA: writer.writeCData(xmlr.getText()); break; case XMLEvent.COMMENT: writer.writeComment(xmlr.getText()); break; case XMLEvent.ENTITY_REFERENCE: writer.writeEntityRef(xmlr.getLocalName()); break; case XMLEvent.START_DOCUMENT: String encoding = xmlr.getCharacterEncodingScheme(); String version = xmlr.getVersion(); if (encoding != null && version != null) { writer.writeStartDocument(encoding, version); } else if (version != null) { writer.writeStartDocument(xmlr.getVersion()); } break; case XMLEvent.END_DOCUMENT: writer.writeEndDocument(); break; case XMLEvent.DTD: writer.writeDTD(xmlr.getText()); break; } }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
/** * XML ??//from www .j a va2 s .co m * * @param name "area" / "corp" * @param suffix "" / "c" */ void storeXml(String name, String suffix) { long timestamp = getLzhDao().getZipInfo().getTimestamp().getTime(); Collection<City> cities = getCities(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); ZipEntry entry = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_" + name + "_utf8.xml"); entry.setTime(timestamp); int cnt = 0; try { zos.putNextEntry(entry); OutputStreamWriter writer = new OutputStreamWriter(zos, "UTF-8"); XMLStreamWriter xwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer); xwriter.writeStartDocument("UTF-8", "1.0"); xwriter.writeStartElement("zips"); xwriter.writeAttribute("type", name); for (City city : cities) { ParentChild pc = getParentChildDao().get(city.getCode() + suffix); if (pc == null) { continue; } for (String json : pc.getChildren()) { Zip zip = Zip.fromJson(json); xwriter.writeStartElement("zip"); xwriter.writeAttribute("zip", zip.getCode()); xwriter.writeAttribute("x0402", zip.getX0402()); xwriter.writeAttribute("add1", zip.getAdd1()); xwriter.writeAttribute("add2", zip.getAdd2()); xwriter.writeAttribute("corp", zip.getCorp()); xwriter.writeAttribute("add1Yomi", zip.getAdd1Yomi()); xwriter.writeAttribute("add2Yomi", zip.getAdd2Yomi()); xwriter.writeAttribute("corpYomi", zip.getCorpYomi()); xwriter.writeAttribute("note", zip.getNote()); xwriter.writeEndElement(); ++cnt; } } xwriter.writeEndElement(); xwriter.writeEndDocument(); xwriter.flush(); zos.closeEntry(); zos.finish(); getRawDao().store(baos.toByteArray(), name + "_utf8_xml.zip"); log.info("count: " + cnt); } catch (XMLStreamException e) { log.log(Level.WARNING, "", e); } catch (FactoryConfigurationError e) { log.log(Level.WARNING, "", e); } catch (IOException e) { log.log(Level.WARNING, "", e); } }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void storeX0401Zip() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); long timestamp = getLzhDao().getZipInfo().getTimestamp().getTime(); ZipOutputStream out = new ZipOutputStream(baos); Collection<Pref> prefs = getPrefs(); ZipEntry tsv = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0401_utf8.txt"); ZipEntry csv = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0401_sjis.csv"); ZipEntry json = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0401_utf8.json"); ZipEntry xml = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0401_utf8.xml"); tsv.setTime(timestamp);//from www .j a v a 2s .c o m csv.setTime(timestamp); json.setTime(timestamp); xml.setTime(timestamp); try { out.putNextEntry(tsv); for (Pref pref : prefs) { out.write(new String(pref.getCode() + "\t" + pref.getName() + "\t" + pref.getYomi() + CRLF) .getBytes("UTF-8")); } out.closeEntry(); out.putNextEntry(csv); for (Pref pref : prefs) { out.write(new String(pref.getCode() + "," + pref.getName() + "," + pref.getYomi() + CRLF) .getBytes("MS932")); } out.closeEntry(); out.putNextEntry(json); OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); JSONWriter jwriter = new JSONWriter(writer); jwriter.array(); for (Pref pref : prefs) { jwriter.object().key("code").value(pref.getCode()).key("name").value(pref.getName()).key("yomi") .value(pref.getYomi()).endObject(); } jwriter.endArray(); writer.flush(); out.closeEntry(); out.putNextEntry(xml); XMLStreamWriter xwriter = XMLOutputFactory.newInstance() .createXMLStreamWriter(new OutputStreamWriter(out, "UTF-8")); xwriter.writeStartDocument("UTF-8", "1.0"); xwriter.writeStartElement("x0401s"); for (Pref pref : prefs) { xwriter.writeStartElement("x0401"); xwriter.writeAttribute("code", pref.getCode()); xwriter.writeAttribute("name", pref.getName()); xwriter.writeAttribute("yomi", pref.getYomi()); xwriter.writeEndElement(); } xwriter.writeEndElement(); xwriter.writeEndDocument(); xwriter.flush(); out.closeEntry(); out.finish(); baos.flush(); getRawDao().store(baos.toByteArray(), "x0401.zip"); log.info("prefs: " + prefs.size()); } catch (JSONException e) { log.log(Level.WARNING, "", e); } catch (XMLStreamException e) { log.log(Level.WARNING, "", e); } catch (FactoryConfigurationError e) { log.log(Level.WARNING, "", e); } catch (IOException e) { log.log(Level.WARNING, "", e); } }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void storeX0402Zip() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); long timestamp = getLzhDao().getZipInfo().getTimestamp().getTime(); ZipOutputStream out = new ZipOutputStream(baos); Collection<City> cities = getCities(); ZipEntry tsv = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0402_utf8.txt"); ZipEntry csv = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0402_sjis.csv"); ZipEntry json = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0402_utf8.json"); ZipEntry xml = new ZipEntry(FILENAME_DATE_FORMAT.format(new Date(timestamp)) + "_x0402_utf8.xml"); tsv.setTime(timestamp);/*from www.j a v a 2s .c om*/ csv.setTime(timestamp); json.setTime(timestamp); xml.setTime(timestamp); try { out.putNextEntry(tsv); for (City city : cities) { out.write(new String(city.getCode() + "\t" + city.getName() + "\t" + city.getYomi() + "\t" + ((city.getExpiration().getTime() < new Date().getTime()) ? "" : "") + CRLF) .getBytes("UTF-8")); } out.closeEntry(); out.putNextEntry(csv); for (City city : cities) { out.write(new String(city.getCode() + "," + city.getName() + "," + city.getYomi() + "," + ((city.getExpiration().getTime() < new Date().getTime()) ? "" : "") + CRLF) .getBytes("MS932")); } out.closeEntry(); out.putNextEntry(json); OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); JSONWriter jwriter = new JSONWriter(writer); jwriter.array(); for (City city : cities) { jwriter.object().key("code").value(city.getCode()).key("name").value(city.getName()).key("yomi") .value(city.getYomi()).key("expired") .value((city.getExpiration().getTime() < new Date().getTime()) ? "true" : "false") .endObject(); } jwriter.endArray(); writer.flush(); out.closeEntry(); out.putNextEntry(xml); XMLStreamWriter xwriter = XMLOutputFactory.newInstance() .createXMLStreamWriter(new OutputStreamWriter(out, "UTF-8")); xwriter.writeStartDocument("UTF-8", "1.0"); xwriter.writeStartElement("x0402s"); for (City city : cities) { xwriter.writeStartElement("x0402"); xwriter.writeAttribute("code", city.getCode()); xwriter.writeAttribute("name", city.getName()); xwriter.writeAttribute("yomi", city.getYomi()); xwriter.writeAttribute("expired", (city.getExpiration().getTime() < new Date().getTime()) ? "true" : "false"); xwriter.writeEndElement(); } xwriter.writeEndElement(); xwriter.writeEndDocument(); xwriter.flush(); out.closeEntry(); out.finish(); baos.flush(); getRawDao().store(baos.toByteArray(), "x0402.zip"); log.info("cities: " + cities.size()); } catch (JSONException e) { log.log(Level.WARNING, "", e); } catch (XMLStreamException e) { log.log(Level.WARNING, "", e); } catch (FactoryConfigurationError e) { log.log(Level.WARNING, "", e); } catch (IOException e) { log.log(Level.WARNING, "", e); } }
From source file:com.github.lindenb.jvarkit.tools.vcfcmp.VcfCompareCallers.java
@Override public Collection<Throwable> call() throws Exception { htsjdk.samtools.util.IntervalTreeMap<Boolean> capture = null; PrintWriter exampleWriter = null; XMLStreamWriter exampleOut = null; PrintStream pw = null;// ww w. j ava 2s.co m VcfIterator vcfInputs[] = new VcfIterator[] { null, null }; VCFHeader headers[] = new VCFHeader[] { null, null }; final List<String> args = getInputFiles(); try { if (args.size() == 1) { LOG.info("Reading from stdin and " + args.get(0)); vcfInputs[0] = VCFUtils.createVcfIteratorStdin(); vcfInputs[1] = VCFUtils.createVcfIterator(args.get(0)); } else if (args.size() == 2) { LOG.info("Reading from stdin and " + args.get(0) + " and " + args.get(1)); vcfInputs[0] = VCFUtils.createVcfIterator(args.get(0)); vcfInputs[1] = VCFUtils.createVcfIterator(args.get(1)); } else { return wrapException(getMessageBundle("illegal.number.of.arguments")); } if (super.captureFile != null) { LOG.info("Reading " + super.captureFile); capture = super.readBedFileAsBooleanIntervalTreeMap(super.captureFile); } for (int i = 0; i < vcfInputs.length; ++i) { headers[i] = vcfInputs[i].getHeader(); } /* dicts */ final SAMSequenceDictionary dict0 = headers[0].getSequenceDictionary(); final SAMSequenceDictionary dict1 = headers[1].getSequenceDictionary(); final Comparator<VariantContext> ctxComparator; if (dict0 == null && dict1 == null) { ctxComparator = VCFUtils.createChromPosRefComparator(); } else if (dict0 != null && dict1 != null) { if (!SequenceUtil.areSequenceDictionariesEqual(dict0, dict1)) { return wrapException(getMessageBundle("not.the.same.sequence.dictionaries")); } ctxComparator = VCFUtils.createTidPosRefComparator(dict0); } else { return wrapException(getMessageBundle("not.the.same.sequence.dictionaries")); } /* samples */ Set<String> samples0 = new HashSet<>(headers[0].getSampleNamesInOrder()); Set<String> samples1 = new HashSet<>(headers[1].getSampleNamesInOrder()); Set<String> samples = new TreeSet<>(samples0); samples.retainAll(samples1); if (samples.size() != samples0.size() || samples.size() != samples1.size()) { LOG.warn("Warning: Not the same samples set. Using intersection of both lists."); } if (samples.isEmpty()) { return wrapException("No common samples"); } Map<String, Counter<Category>> sample2info = new HashMap<String, Counter<Category>>(samples.size()); for (String sampleName : samples) { sample2info.put(sampleName, new Counter<Category>()); } if (super.exampleFile != null) { exampleWriter = new PrintWriter(exampleFile, "UTF-8"); XMLOutputFactory xof = XMLOutputFactory.newFactory(); exampleOut = xof.createXMLStreamWriter(exampleWriter); exampleOut.writeStartDocument("UTF-8", "1.0"); exampleOut.writeStartElement("compare-callers"); } SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(dict0); VariantContext buffer[] = new VariantContext[vcfInputs.length]; VariantContext prev[] = new VariantContext[vcfInputs.length]; for (;;) { VariantContext smallest = null; //refill buffer for (int i = 0; i < vcfInputs.length; ++i) { if (buffer[i] == null && vcfInputs[i] != null) { if (vcfInputs[i].hasNext()) { buffer[i] = vcfInputs[i].peek(); /* check data are sorted */ if (prev[i] != null && ctxComparator.compare(prev[i], buffer[i]) > 0) { return wrapException("Input " + (i + 1) + "/2 is not sorted" + (((i == 0 && dict0 == null) || (i == 1 && dict1 == null)) ? "on chrom/pos/ref" : "on sequence dictionary") + ". got\n" + buffer[i] + "\nafter\n" + prev[i]); } } else { vcfInputs[i].close(); vcfInputs[i] = null; } } if (buffer[i] != null) { if (smallest == null || ctxComparator.compare(buffer[i], smallest) < 0) { smallest = buffer[i]; } } } if (smallest == null) break; VariantContext ctx0 = null; VariantContext ctx1 = null; Interval interval = null; if (buffer[0] != null && ctxComparator.compare(buffer[0], smallest) == 0) { prev[0] = progress.watch(vcfInputs[0].next()); ctx0 = prev[0]; buffer[0] = null; interval = new Interval(ctx0.getContig(), ctx0.getStart(), ctx0.getEnd()); } if (buffer[1] != null && ctxComparator.compare(buffer[1], smallest) == 0) { prev[1] = progress.watch(vcfInputs[1].next()); ctx1 = prev[1]; buffer[1] = null; interval = new Interval(ctx1.getContig(), ctx1.getStart(), ctx1.getEnd()); } boolean in_capture = true; if (capture != null && interval != null) { in_capture = capture.containsOverlapping(interval); } for (final String sampleName : sample2info.keySet()) { final Counter<Category> sampleInfo = sample2info.get(sampleName); Genotype g0 = (ctx0 == null ? null : ctx0.getGenotype(sampleName)); Genotype g1 = (ctx1 == null ? null : ctx1.getGenotype(sampleName)); if (g0 != null && (g0.isNoCall() || !g0.isAvailable())) g0 = null; if (g1 != null && (g1.isNoCall() || !g1.isAvailable())) g1 = null; if (g0 == null && g1 == null) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.both_missing); continue; } else if (g0 != null && g1 == null) { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_only_1); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1); if (ctx0.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1_indel); } else if (ctx0.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_1_snp); } continue; } else if (g0 == null && g1 != null) { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_only_2); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2); if (ctx1.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2_indel); } else if (ctx1.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.unique_to_file_2_snp); } continue; } else { if (!in_capture) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.off_target_both); continue; } watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context); if (ctx0.isIndel() && ctx1.isIndel()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_indel); } else if (ctx0.isSNP() && ctx1.isSNP()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_snp); } if ((ctx0.hasID() && !ctx1.hasID()) || (!ctx0.hasID() && ctx1.hasID()) || (ctx0.hasID() && ctx1.hasID() && !ctx0.getID().equals(ctx1.getID()))) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.common_context_discordant_id); } if (g0.sameGenotype(g1)) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same); if (g0.isHomRef()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_hom_ref); } if (g0.isHomVar()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_hom_var); } else if (g0.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_and_same_het); } } else { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant); if (g0.isHom() && g1.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_hom1_het2); } else if (g0.isHet() && g1.isHom()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_het1_hom2); } else if (g0.isHom() && g1.isHom()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_hom1_hom2); } else if (g0.isHet() && g1.isHet()) { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_het1_het2); } else { watch(exampleOut, ctx0, ctx1, g0, g1, sampleName, sampleInfo, Category.called_but_discordant_others); } } } } } progress.finish(); pw = openFileOrStdoutAsPrintStream(); pw.print("#Sample"); for (Category c : Category.values()) { pw.print('\t'); pw.print(c.name()); } pw.println(); for (String sample : sample2info.keySet()) { Counter<Category> count = sample2info.get(sample); pw.print(sample); for (Category c : Category.values()) { pw.print('\t'); pw.print(count.count(c)); } pw.println(); if (pw.checkError()) break; } pw.flush(); if (exampleOut != null) { exampleOut.writeEndElement(); exampleOut.writeEndDocument(); exampleOut.flush(); exampleOut.close(); } return RETURN_OK; } catch (Exception err) { return wrapException(err); } finally { if (getOutputFile() != null) CloserUtil.close(pw); CloserUtil.close(exampleWriter); } }
From source file:nl.nn.adapterframework.soap.Wsdl.java
/** * Writes the WSDL to an output stream//from w w w . j a v a 2 s.co m * @param out * @param servlet The servlet what is used as the web service (because this needs to be present in the WSDL) * @throws XMLStreamException * @throws IOException */ public void wsdl(OutputStream out, String servlet) throws XMLStreamException, IOException, ConfigurationException, NamingException { XMLStreamWriter w = WsdlUtils.getWriter(out, isIndent()); w.writeStartDocument(XmlUtils.STREAM_FACTORY_ENCODING, "1.0"); w.setPrefix(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.setPrefix(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.setPrefix(soapPrefix, soapNamespace); if (jmsActive) { if (esbSoap) { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, ESB_SOAP_JMS_NAMESPACE); w.setPrefix(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } else { w.setPrefix(SOAP_JMS_NAMESPACE_PREFIX, SOAP_JMS_NAMESPACE); } } w.setPrefix(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.setPrefix(prefix, namespaceByPrefix.get(prefix)); } w.writeStartElement(WSDL_NAMESPACE, "definitions"); { w.writeNamespace(WSDL_NAMESPACE_PREFIX, WSDL_NAMESPACE); w.writeNamespace(XSD_NAMESPACE_PREFIX, XSD_NAMESPACE); w.writeNamespace(soapPrefix, soapNamespace); if (esbSoap) { w.writeNamespace(ESB_SOAP_JNDI_NAMESPACE_PREFIX, ESB_SOAP_JNDI_NAMESPACE); } w.writeNamespace(getTargetNamespacePrefix(), getTargetNamespace()); for (String prefix : namespaceByPrefix.keySet()) { w.writeNamespace(prefix, namespaceByPrefix.get(prefix)); } w.writeAttribute("targetNamespace", getTargetNamespace()); documentation(w); types(w); messages(w); portType(w); binding(w); service(w, servlet); } w.writeEndDocument(); warnings(w); w.close(); }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
public static void main(String[] args) { logger.info("Starting application [ rtd ] ..."); try {//from w w w. j a v a 2 s . c o m config.addConfiguration( new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME))); HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT); EodDataProvider eodDataProvider = null; OutputStream out = new FileOutputStream(OUTPUT_FILENAME); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(out); eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME); writer.writeStartDocument("utf-8", "1.0"); writer.writeCharacters(NEWLINE); writer.writeComment("Test data for running DataScraper unit tests against"); writer.writeCharacters(NEWLINE); writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI); writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME); writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI); writer.writeCharacters(NEWLINE); serializeExchanges(eodDataProvider, writer); serializeSymbols(eodDataProvider, writer); serializeQuotes(eodDataProvider, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (ConfigurationException ce) { logger.error(ce.toString()); ce.printStackTrace(); } catch (Exception e) { logger.error(e.toString()); logger.error(e); } logger.info("Exiting application [ rtd ] ..."); }
From source file:org.activiti.bpmn.converter.export.DefinitionsRootExport.java
@SuppressWarnings("unchecked") public static void writeRootElement(BpmnModel model, XMLStreamWriter xtw, String encoding) throws Exception { xtw.writeStartDocument(encoding, "1.0"); // start definitions root element xtw.writeStartElement(ELEMENT_DEFINITIONS); xtw.setDefaultNamespace(BPMN2_NAMESPACE); xtw.writeDefaultNamespace(BPMN2_NAMESPACE); xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE); xtw.writeNamespace(XSD_PREFIX, SCHEMA_NAMESPACE); xtw.writeNamespace(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE); xtw.writeNamespace(BPMNDI_PREFIX, BPMNDI_NAMESPACE); xtw.writeNamespace(OMGDC_PREFIX, OMGDC_NAMESPACE); xtw.writeNamespace(OMGDI_PREFIX, OMGDI_NAMESPACE); for (String prefix : model.getNamespaces().keySet()) { if (!defaultNamespaces.contains(prefix) && StringUtils.isNotEmpty(prefix)) xtw.writeNamespace(prefix, model.getNamespaces().get(prefix)); }// w w w .ja v a 2s. com xtw.writeAttribute(TYPE_LANGUAGE_ATTRIBUTE, SCHEMA_NAMESPACE); xtw.writeAttribute(EXPRESSION_LANGUAGE_ATTRIBUTE, XPATH_NAMESPACE); if (StringUtils.isNotEmpty(model.getTargetNamespace())) { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, model.getTargetNamespace()); } else { xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, PROCESS_NAMESPACE); } BpmnXMLUtil.writeCustomAttributes(model.getDefinitionsAttributes().values(), xtw, model.getNamespaces(), defaultAttributes); }