/** {@inheritDoc} */ @Override public void print(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); if (options.pretty) { ser.setIndent(2); } else { ser.setIndent(0); } ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
protected void writeXML(final Document doc, final File f) throws IOException, XMLException { try { OutputStream out = new FileOutputStream(f); out = new BufferedOutputStream(out); // getDocumentCharset(f) - to retrieve the charset encoding attribute Serializer serializer = new Serializer(out, XMLUtil.getDocumentCharset(f)); serializer.write(doc); out.close(); } catch (IOException ex) { throw new XMLException(ex.getMessage(), ex); } }
public static String prettyXml(Document doc) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Serializer serializer = new Serializer(out); serializer.setIndent(2); serializer.write(doc); return out.toString("UTF-8"); }
private static void writeFile( final File file, final Document document) throws IOException { JSCMain.LOG.info("writing " + file); final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(file)); try { final Serializer s = new Serializer(stream); s.write(document); s.flush(); } finally { stream.flush(); stream.close(); } }
/** overrides element writing. allows updating of XOM before * * @param element * @throws IOException */ protected void write(Element element) throws IOException { if (element instanceof CMLElement) { // ((CMLElement) element).updateXOM(); } super.write(element); }
/** * Creates a {@link Serializer} to be used for writing the response to. * * <p>Default implementation uses the UTF-8 encoding and does not set any options, but this may be changed in * subclasses. * * @param outputStream the output stream to serialize to * @return the serializer */ protected Serializer createSerializer(OutputStream outputStream) { return new Serializer(outputStream); }
public static String xmlFromDocument(Document doc) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serializer serializer = new Serializer(baos, "UTF-8"); serializer.setIndent(4); serializer.write(doc); return baos.toString("UTF-8"); }
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { final Serializer s = new Serializer(os, "UTF-8"); s.write(doc); s.flush();
/** convenience method to serialize the element. * * @param os * @param indent to indent lines by (non-zero may muck up whitespace) * @throws IOException */ public void serialize(OutputStream os, int indent) throws IOException { Document doc = new Document((CMLElement)this.copy()); Serializer serializer = new Serializer(os); serializer.write(doc); }
/** overrides attribute writing. * <p> * Writes an attribute in the form <code><i>name</i>="<i>value</i>"</code>. * Characters in the attribute value are escaped as necessary. * </p> * * @param attribute * the <code>Attribute</code> to write * * @throws IOException * if the underlying output stream encounters an I/O error * @throws UnavailableCharacterException * if the attribute name contains a character that is not * available in the current encoding * */ protected void write(Attribute attribute) throws IOException { // not sure which attributes might trigger this super.write(attribute); }
/** * Creates a {@link Serializer} to be used for writing the response to. * <p/> * Default implementation uses the UTF-8 encoding and does not set any options, but this may be changed in * subclasses. * * @param outputStream the output stream to serialize to * @return the serializer */ protected Serializer createSerializer(OutputStream outputStream) { return new Serializer(outputStream); }
@Deprecated public static String indentXML(final String in) throws XMLException, IOException { try { Builder parser = new Builder(); Document doc = parser.build(in, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serializer serializer = new Serializer(baos); serializer.setIndent(4); serializer.setMaxLength(69); serializer.write(doc); return new String(baos.toByteArray()); } catch (ParsingException ex) { // LOG.log(Level.SEVERE, null, ex); throw new XMLException("XML indentation failed.", ex); } } }
public void write(final OutputStream os, final Charset charset) throws IOException { if (doc == null) throw new IllegalStateException("Call parse() before calling this method!"); // Display output: Serializer serializer = new Serializer(os, charset.name()); serializer.setIndent(4); serializer.write(doc); }
final KSXOMSerializerType<KSEvaluation> xs = KSXOMSerializer.Companion.create(imports, includes); final Serializer s = new Serializer(os, "UTF-8"); s.write(new Document((Element) xs.serialize(b))); s.flush();
getLog().info("Dumping to " + resolvedXML.getAbsolutePath()); final BufferedOutputStream bos = new BufferedOutputStream(fos); final Serializer serializer = new Serializer(bos); serializer.write(doc); bos.flush(); bos.close();
private void writeChanges(Document pom) { Serializer serializer = createSerialiser(); try { serializer.write(pom); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Creates a {@link Serializer} to be used for writing the response to. * * <p>Default implementation uses the UTF-8 encoding and does not set any options, but this may be changed in * subclasses. * * @param outputStream the output stream to serialize to * @return the serializer */ protected Serializer createSerializer(OutputStream outputStream) { return new Serializer(outputStream); }
public static void format(OutputStream os, Document doc) throws Exception { Serializer serializer = new Serializer(os,"ISO-8859-1"); serializer.setIndent(4); serializer.setMaxLength(60); serializer.write(doc); serializer.flush(); } public static void
/** * * @param doc * @return */ public static String serialize(final Node doc) throws CouldNotProcessException { final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); final Serializer ser = new Serializer(outStream); try { ser.setIndent(3); ser.write(doc.getDocument()); return outStream.toString(); } catch (IOException ex) { throw new CouldNotProcessException("Couldn't transform doc to prettyXMLString. Returning old document.", ex); } }
"-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")); final Serializer serial = new Serializer(output, "UTF-8"); serial.write(doc); serial.flush();