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); } }
@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); } } }
/** {@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(); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
protected Serializer makeSerializer(OutputStream out) throws UnsupportedEncodingException { return new Serializer(out, "UTF-8"); } }
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"); }
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"); }
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); }
private static void printDocument(Document document) { Serializer serializer = new Serializer(System.out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } } }
private static void printDocument(Document document) { Serializer serializer = new Serializer(System.out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } } }
/** 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); }
public static String graphToXml(Graph graph) { Document document = new Document(convertToXml(graph)); OutputStream out = new ByteArrayOutputStream(); Serializer serializer = new Serializer(out); serializer.setLineSeparator("\n"); serializer.setIndent(2); try { serializer.write(document); } catch (IOException e) { throw new RuntimeException(e); } return out.toString(); }
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
public static void xmlPrint(Annotation annotation, OutputStream os, Options options) throws IOException { Document xmlDoc = annotationToDoc(annotation, options); Serializer ser = new Serializer(os, options.encoding); ser.setIndent(2); ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** * Displays the output of all annotators in XML format. * @param annotation Contains the output of all annotators * @param os The output stream * @throws IOException */ public void xmlPrint(Annotation annotation, OutputStream os) throws IOException { Document xmlDoc = annotationToDoc(annotation); Serializer ser = new Serializer(os, "UTF-8"); ser.setIndent(2); ser.setMaxLength(0); ser.write(xmlDoc); ser.flush(); }
/** {@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(); }
@Test public void testCdkBondToCMLBond_Hatch() throws IOException { IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); IBond bond = builder.newInstance(IBond.class); bond.setOrder(IBond.Order.SINGLE); bond.setStereo(IBond.Stereo.DOWN); Convertor convertor = new Convertor(true, null); CMLBond cmlBond = convertor.cdkBondToCMLBond(bond); ByteArrayOutputStream out = new ByteArrayOutputStream(); Serializer serializer = new Serializer(out, "UTF-8"); serializer.write(new Document(cmlBond)); out.close(); String expected = "<bondStereo dictRef=\"cml:H\">H</bondStereo>"; String actual = new String(out.toByteArray()); Assert.assertTrue(actual.contains(expected)); }