/** * Writes an NcML element to a string. * * @param elem an NcML element. * @return the string that represents the NcML document. */ public String writeToString(Element elem) { try (StringWriter writer = new StringWriter()) { writeToWriter(elem, writer); return writer.toString(); } catch (IOException e) { throw new AssertionError("CAN'T HAPPEN: StringWriter.close() is a no-op.", e); } }
/** * Writes an NcML element to an output stream. * * @param elem an NcML element. * @param outStream the stream to write the NcML document to. Will be closed at end of the method. * @throws IOException if there's any problem writing. */ public void writeToStream(Element elem, OutputStream outStream) throws IOException { try (Writer writer = new BufferedWriter(new OutputStreamWriter( new BufferedOutputStream(outStream), xmlFormat.getEncoding()))) { writeToWriter(elem, writer); } }
/** * Write the NcML representation: dont show coodinate values * * @param writer : write to this Writer, should have encoding of UTF-8 if applicable. Will be closed at end of the * method. * @param uri use this for the url attribute; if null use getLocation(). * @throws IOException if error * @see NcMLWriter#writeToWriter */ public void writeNcML(java.io.Writer writer, String uri) throws IOException { NcMLWriter ncmlWriter = new NcMLWriter(); Element netcdfElem = ncmlWriter.makeNetcdfElement(this, uri); ncmlWriter.writeToWriter(netcdfElem, writer); }
ncmlWriter.writeToWriter(netcdfElement, writer);