public IndentXmlStreamWriter(Writer out) throws XMLStreamException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); this.indent = 0; this.out = factory.createXMLStreamWriter(out); }
FileOutputStream fos = null; try { fos = new FileOutputStream("test.xml"); XMLOutputFactory xmlOutFact = XMLOutputFactory.newInstance(); XMLStreamWriter writer = xmlOutFact.createXMLStreamWriter(fos); writer.writeStartDocument(); writer.writeStartElement("test"); // write stuff writer.writeEndElement(); writer.flush(); } catch(IOException exc) { } catch(XMLStreamException exc) { } finally { }
@Override public void write(final ConfigurableComponent configurableComponent, final OutputStream streamToWriteTo, final boolean includesAdditionalDocumentation) throws IOException { try { XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( streamToWriteTo, "UTF-8"); xmlStreamWriter.writeDTD("<!DOCTYPE html>"); xmlStreamWriter.writeStartElement("html"); xmlStreamWriter.writeAttribute("lang", "en"); writeHead(configurableComponent, xmlStreamWriter); writeBody(configurableComponent, xmlStreamWriter, includesAdditionalDocumentation); xmlStreamWriter.writeEndElement(); xmlStreamWriter.close(); } catch (XMLStreamException | FactoryConfigurationError e) { throw new IOException("Unable to create XMLOutputStream", e); } }
@Override public String getFingerprint() throws AuthorizationAccessException { final List<AccessPolicy> policies = new ArrayList<>(getAccessPolicies()); Collections.sort(policies, Comparator.comparing(AccessPolicy::getIdentifier)); XMLStreamWriter writer = null; final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("accessPolicies"); for (AccessPolicy policy : policies) { writePolicy(writer, policy); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { // nothing to do here } } } return out.toString(); }
public WStringArrayTypeNode(BinaryReader binaryReader, ChunkHeader chunkHeader, BxmlNode parent, int length) throws IOException { super(binaryReader, chunkHeader, parent, length); String raw; if (length >= 0) { raw = binaryReader.readWString(length / 2); } else { int binaryLength = binaryReader.readWord(); raw = binaryReader.readWString(binaryLength / 2); } ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { XMLStreamWriter xmlStreamWriter = XML_OUTPUT_FACTORY.createXMLStreamWriter(stream, "UTF-8"); for (String s : raw.split("\u0000")) { xmlStreamWriter.writeStartElement("string"); try { xmlStreamWriter.writeCharacters(s); } finally { xmlStreamWriter.writeEndElement(); } } xmlStreamWriter.close(); } catch (XMLStreamException e) { throw new IOException(e); } value = stream.toString("UTF-8"); }
public static void serialize(Element element, Writer writer) throws IOException, XMLStreamException { XMLStreamWriter xml = outputFactory.createXMLStreamWriter(writer); serialize(element, xml); xml.writeEndDocument(); xml.flush(); }
final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); try (OutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(tempPath, WRITE, CREATE_NEW, DSYNC))) { try (AutoCloseableXMLStreamWriterHolder holder = new AutoCloseableXMLStreamWriterHolder(xmlOutputFactory.createXMLStreamWriter(outputStream))) { final XMLStreamWriter streamWriter = holder.getXmlStreamWriter(); streamWriter.writeStartDocument(); streamWriter.writeCharacters("\n"); streamWriter.writeStartElement("identity"); streamWriter.writeEndDocument(); } catch (XMLStreamException e) { throw ElytronMessages.log.fileSystemRealmFailedToWrite(tempPath, name, e);
public static String policyComponentToString(PolicyComponent policyComponent) throws XMLStreamException, FactoryConfigurationError { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLStreamWriter writer = XMLOutputFactory.newInstance() .createXMLStreamWriter(baos); policyComponent.serialize(writer); writer.flush(); return baos.toString(); }
public XmlTextWriter() { stream = new StringWriter(); try { XMLOutputFactory factory = XMLOutputFactory.newInstance(); writer = factory.createXMLStreamWriter(stream); writer.writeStartDocument("UTF-8", "1.0"); } catch (Exception e) { throw new RuntimeException("Failed to initialize xml writer: ", e); } }
public static String jsonToXml(@NotNull JsonObject json, @NotNull String rootName) throws XMLStreamException { Writer xml = new StringWriter(); // Create an XML stream writer XMLStreamWriter xmlw = XML_OUTPUT_FACTORY.createXMLStreamWriter(xml); // Write XML prologue xmlw.writeStartDocument(); // perform real conversion jsonToXml(xmlw, json, rootName); // Close the writer to flush the output xmlw.close(); return xml.toString(); }
data.writer = XML_OUT_FACTORY.createXMLStreamWriter( getTrans().getServletPrintWriter() ); if ( meta.getEncoding() != null && meta.getEncoding().length() > 0 ) { data.writer.writeStartDocument( meta.getEncoding(), "1.0" ); } else { data.writer.writeStartDocument( Const.XML_ENCODING, "1.0" ); data.writer = XML_OUT_FACTORY.createXMLStreamWriter( outputStream, meta.getEncoding() ); data.writer.writeStartDocument( meta.getEncoding(), "1.0" ); } else { logBasic( "Opening output stream in default encoding : " + Const.XML_ENCODING ); data.writer = XML_OUT_FACTORY.createXMLStreamWriter( outputStream ); data.writer.writeStartDocument( Const.XML_ENCODING, "1.0" );
final StringWriter out = new StringWriter(); try { writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); writer.writeStartDocument(); writer.writeStartElement("managedAuthorizations"); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { throw new AuthorizationAccessException("Unable to generate fingerprint", e); if (writer != null) { try { writer.close(); } catch (XMLStreamException e) {
private void handleContainerLocation(HttpServletResponse response) throws IOException { response.setCharacterEncoding(UTF_8); try (Writer writer = response.getWriter()) { response.setContentType(XML_CONTENT_TYPE); XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter( writer); xml.writeStartDocument(); // TODO: using us-standard semantics but could emit actual location xml.writeStartElement("LocationConstraint"); xml.writeDefaultNamespace(AWS_XMLNS); xml.writeEndElement(); xml.flush(); } catch (XMLStreamException xse) { throw new IOException(xse); } }
public XmlDocumentationWriter(final OutputStream out) throws XMLStreamException { this.writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8"); }
XMLStreamWriter xsw = xof.createXMLStreamWriter(os, "UTF-8"); xsw.close();
private void entitySet(final Writer outWriter, final EntityCollection entitySet) throws XMLStreamException, EdmPrimitiveTypeException { final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter); startDocument(writer, Constants.ATOM_ELEM_FEED); entitySet(writer, entitySet); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); }
OutputStream destination = ...; XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter xml = outputFactory.createXMLStreamWriter(destination); xml.writeStartDocument(); xml.writeStartElement("html"); xml.writeDefaultNamespace("http://www.w3.org/1999/xhtml"); xml.writeStartElement("head"); xml.writeStartElement("title"); xml.writeCharacters("The title of the page"); xml.writeEndElement(); xml.writeEndElement(); xml.writeEndElement(); xml.writeEndDocument();
private void saveTempfile() { try { File file = new File("metadata.xml"); FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out); reportsElement.serialize(writer, true); writer.flush(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } }
protected XMLStreamWriter initiateWritter(FileOutputStream outputFileStream, File sourceFile) throws XMLStreamException, IOException { XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = xof.createXMLStreamWriter(outputFileStream, "UTF-8"); // System.out.println(outputPath + sourcefileName + ".knowtator.xml"); xtw.writeStartDocument("UTF-8", "1.0"); xtw.writeStartElement("annotations"); xtw.writeAttribute("textSource", sourceFile.getAbsolutePath()); return xtw; }
public void toXml(Struct struct, Writer writer) { try { XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter xmlWriter = factory.createXMLStreamWriter(writer); xmlWriter.setDefaultNamespace(STRUCT_NAMESPACE); serializeStruct(struct, xmlWriter, 0); xmlWriter.close(); } catch (Exception e) { log.error("Error orccured during serialization of struct to XML", e); } }