List of usage examples for javax.xml.stream XMLStreamWriter writeEndDocument
public void writeEndDocument() throws XMLStreamException;
From source file:com.microsoft.windowsazure.services.table.client.AtomPubParser.java
/** * Reserved for internal use. Writes a single entity to the specified <code>XMLStreamWriter</code> as a complete XML * document.//w w w .j a v a 2s . c o m * * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param xmlw * The <code>XMLStreamWriter</code> to write the entity to. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * * @throws XMLStreamException * if an error occurs creating or accessing the stream. * @throws StorageException * if a Storage service error occurs. */ protected static void writeSingleEntityToStream(final TableEntity entity, final boolean isTableEntry, final XMLStreamWriter xmlw, final OperationContext opContext) throws XMLStreamException, StorageException { // default is UTF8 xmlw.writeStartDocument("UTF-8", "1.0"); writeEntityToStream(entity, isTableEntry, xmlw, opContext); // end doc xmlw.writeEndDocument(); xmlw.flush(); }
From source file:com.norconex.jefmon.model.ConfigurationDAO.java
public static void saveConfig(JEFMonConfig config) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Saving JEF config to: " + CONFIG_FILE); }//w w w .j ava 2 s . c o m if (!CONFIG_FILE.exists()) { File configDir = new File(FilenameUtils.getFullPath(CONFIG_FILE.getAbsolutePath())); if (!configDir.exists()) { LOG.debug("Creating JEF Monitor config directory for: " + CONFIG_FILE); configDir.mkdirs(); } } OutputStream out = new FileOutputStream(CONFIG_FILE); XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter xml = factory.createXMLStreamWriter(out); xml.writeStartDocument(); xml.writeStartElement("jefmon-config"); xml.writeStartElement("instance-name"); xml.writeCharacters(config.getInstanceName()); xml.writeEndElement(); xml.writeStartElement("default-refresh-interval"); xml.writeCharacters(Integer.toString(config.getDefaultRefreshInterval())); xml.writeEndElement(); saveRemoteUrls(xml, config.getRemoteInstanceUrls()); saveMonitoredPaths(xml, config.getMonitoredPaths()); saveJobActions(xml, config.getJobActions()); xml.writeEndElement(); xml.writeEndDocument(); xml.flush(); xml.close(); } catch (XMLStreamException e) { throw new IOException("Cannot save as XML.", e); } out.close(); }
From source file:com.predic8.membrane.core.config.AbstractXmlElement.java
public String toXml() throws Exception { StringWriter sw = new StringWriter(); XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); w.writeStartDocument();/*from w w w . j av a2 s .co m*/ write(w); w.writeEndDocument(); return sw.toString(); }
From source file:Main.java
public final String getMessage() throws Exception { Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty("jaxb.encoding", "ISO-8859-1"); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(baos, (String) jaxbMarshaller.getProperty(Marshaller.JAXB_ENCODING)); xmlStreamWriter.writeStartDocument((String) jaxbMarshaller.getProperty(Marshaller.JAXB_ENCODING), "1.0"); jaxbMarshaller.marshal(this, xmlStreamWriter); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close();/* w w w . j a v a 2 s. c o m*/ return new String(baos.toByteArray()); }
From source file:eu.scape_project.planning.xml.ProjectExportAction.java
/** * Dumps binary data to provided file. It results in an XML file with a * single element: data.// ww w. ja v a 2s . co m * * @param id * @param data * @param f * @param encoder * @throws IOException */ private static void writeBinaryData(int id, InputStream data, File f) throws IOException { XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = factory.createXMLStreamWriter(new FileWriter(f)); writer.writeStartDocument(PlanXMLConstants.ENCODING, "1.0"); writer.writeStartElement("data"); writer.writeAttribute("id", "" + id); Base64InputStream base64EncodingIn = new Base64InputStream(data, true, PlanXMLConstants.BASE64_LINE_LENGTH, PlanXMLConstants.BASE64_LINE_BREAK); OutputStream out = new WriterOutputStream(new XMLStreamContentWriter(writer), PlanXMLConstants.ENCODING); // read the binary data and encode it on the fly IOUtils.copy(base64EncodingIn, out); out.flush(); // all data is written - end writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.maodian.flyingcat.xmpp.state.DefaultElementVisitor.java
@Override public State handleSASL(XmppContext ctx, Auth auth) throws XMLStreamException { ctx.login(auth.getAuthcid(), auth.getPassword()); StringWriter writer = new StringWriter(); XMLStreamWriter xmlsw = XMLOutputFactoryHolder.getXMLOutputFactory().createXMLStreamWriter(writer); xmlsw.setPrefix("", XmppNamespace.SASL); xmlsw.writeEmptyElement(XmppNamespace.SASL, "success"); xmlsw.writeDefaultNamespace(XmppNamespace.SASL); xmlsw.writeEndDocument(); ctx.flush(writer.toString());// w ww .j a v a 2s . c o m return ctx.getGlobalContext().getAuthenticatedStreamState(); }
From source file:org.maodian.flyingcat.xmpp.state.DefaultElementVisitor.java
@Override public State handleTLS(XmppContext xmppCtx, TLS tls) throws XMLStreamException { ChannelHandlerContext ctx = xmppCtx.getNettyChannelHandlerContext(); SSLEngine engine = SecureSslContextFactory.getServerContext().createSSLEngine(); engine.setUseClientMode(false);/*from ww w. j a va 2 s . c om*/ SslHandler sslHandler = new SslHandler(engine, true); sslHandler.sslCloseFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { log.info("Close the socket since SSL connection has been closed by client"); future.channel().close(); } }); ctx.pipeline().addFirst("ssl", sslHandler); StringWriter writer = new StringWriter(); XMLStreamWriter xmlsw = XMLOutputFactoryHolder.getXMLOutputFactory().createXMLStreamWriter(writer); xmlsw.writeEmptyElement("", "proceed", XmppNamespace.TLS); xmlsw.setPrefix("", XmppNamespace.TLS); xmlsw.writeNamespace("", XmppNamespace.TLS); xmlsw.writeEndDocument(); xmppCtx.flush(writer.toString()); return xmppCtx.getGlobalContext().getTlsStreamState(); }
From source file:net.solarnetwork.util.JavaBeanXmlSerializer.java
private void endXml(XMLStreamWriter writer) { try {// www . jav a2s . c o m writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { // ignore this } finally { SDF.remove(); } }
From source file:de.shadowhunt.subversion.internal.ProbeServerOperation.java
@Override protected HttpUriRequest createRequest() { final Writer body = new StringBuilderWriter(); try {/*from w w w . j a v a 2 s .c o m*/ final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body); writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0); writer.writeStartElement("options"); writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE); writer.writeEmptyElement("activity-collection-set"); writer.writeEndElement(); //options writer.writeEndDocument(); writer.close(); } catch (final XMLStreamException e) { throw new SubversionException("could not create request body: " + e.getMessage(), e); } final DavTemplateRequest request = new DavTemplateRequest("OPTIONS", repository); request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML)); return request; }
From source file:com.microsoft.windowsazure.storage.table.TableParser.java
/** * Reserved for internal use. Writes a single entity to the specified <code>OutputStream</code> as a complete XML * document.//from w w w. j a v a2 s . com * * @param entity * The instance implementing {@link TableEntity} to write to the output stream. * @param isTableEntry * A flag indicating the entity is a reference to a table at the top level of the storage service when * <code>true<code> and a reference to an entity within a table when <code>false</code>. * @param opContext * An {@link OperationContext} object used to track the execution of the operation. * @param outStream * The <code>OutputStream</code> to write the entity to. * * @throws XMLStreamException * if an error occurs creating or accessing the stream. * @throws StorageException * if a Storage service error occurs. */ private static void writeSingleAtomEntity(final StringWriter strWriter, final TableEntity entity, final boolean isTableEntry, final OperationContext opContext) throws XMLStreamException, StorageException { final XMLOutputFactory xmlOutFactoryInst = XMLOutputFactory.newInstance(); XMLStreamWriter xmlw = xmlOutFactoryInst.createXMLStreamWriter(strWriter); // default is UTF8 xmlw.writeStartDocument(Constants.UTF8_CHARSET, "1.0"); writeAtomEntity(entity, isTableEntry, xmlw, opContext); // end doc xmlw.writeEndDocument(); xmlw.flush(); }