|
From: <sa...@us...> - 2004-02-19 12:34:14
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12822/org/jrobin/core Modified Files: FetchData.java RrdDb.java RrdFile.java Log Message: Minor improvements (FetchData dump to XML) Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FetchData.java 10 Nov 2003 08:52:27 -0000 1.2 --- FetchData.java 19 Feb 2004 12:23:57 -0000 1.3 *************** *** 27,30 **** --- 27,33 ---- import java.io.IOException; + import java.io.OutputStream; + import java.io.FileOutputStream; + import java.io.ByteArrayOutputStream; /** *************** *** 342,344 **** --- 345,414 ---- } + /** + * Dumps fetch data to output stream in XML format. + * @param outputStream Output stream to dump fetch data to + * @throws IOException Thrown in case of I/O error + */ + public void exportXml(OutputStream outputStream) throws IOException { + XmlWriter writer = new XmlWriter(outputStream); + writer.startTag("fetch_data"); + writer.startTag("request"); + writer.writeTag("file", request.getParentDb().getRrdFile().getCanonicalFilePath()); + writer.writeComment(Util.getDate(request.getFetchStart())); + writer.writeTag("start", request.getFetchStart()); + writer.writeComment(Util.getDate(request.getFetchEnd())); + writer.writeTag("end", request.getFetchEnd()); + writer.writeTag("resolution", request.getResolution()); + writer.writeTag("cf", request.getConsolFun()); + writer.closeTag(); // request + writer.startTag("datasources"); + for(int i = 0; i < dsNames.length; i++) { + writer.writeTag("name", dsNames[i]); + } + writer.closeTag(); // datasources + writer.startTag("data"); + for(int i = 0; i < timestamps.length; i++) { + writer.startTag("row"); + writer.writeComment(Util.getDate(timestamps[i])); + writer.writeTag("timestamp", timestamps[i]); + writer.startTag("values"); + for(int j = 0; j < dsNames.length; j++) { + writer.writeTag("v", values[j][i]); + } + writer.closeTag(); // values + writer.closeTag(); // row + } + writer.closeTag(); // data + writer.closeTag(); // fetch_data + writer.finish(); + } + + /** + * Dumps fetch data to file in XML format. + * @param filepath Path to destination file + * @throws IOException Thrown in case of I/O error + */ + public void exportXml(String filepath) throws IOException { + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(filepath); + exportXml(outputStream); + } + finally { + if(outputStream != null) { + outputStream.close(); + } + } + } + + /** + * Dumps fetch data in XML format. + * @return String containing XML formatted fetch data + * @throws IOException Thrown in case of I/O error + */ + public String exportXml() throws IOException { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + exportXml(outputStream); + return outputStream.toString(); + } } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdDb.java 2 Dec 2003 10:18:17 -0000 1.9 --- RrdDb.java 19 Feb 2004 12:23:57 -0000 1.10 *************** *** 517,520 **** --- 517,528 ---- /** + * This method is just an alias for {@link #dumpXml(OutputStream) dumpXml} method. + * @throws IOException Thrown in case of I/O related error + */ + public synchronized void exportXml(OutputStream destination) throws IOException { + dumpXml(destination); + } + + /** * <p>Returns string representing internal state of RRD file in XML format. This format * is fully compatible with RRDTool's XML dump format and can be used for conversion *************** *** 531,534 **** --- 539,552 ---- /** + * This method is just an alias for {@link #getXml() getXml} method. + * @return Internal state of RRD file in XML format. + * @throws IOException Thrown in case of I/O related error + * @throws RrdException Thrown in case of JRobin specific error + */ + public synchronized String exportXml() throws IOException, RrdException { + return getXml(); + } + + /** * <p>Dumps internal state of RRD file to XML file. * Use this XML file to convert your JRobin RRD file to RRDTool format.</p> *************** *** 549,557 **** * @throws RrdException Thrown in case of JRobin related error. */ - public synchronized void dumpXml(String filename) throws IOException, RrdException { ! OutputStream destination = new FileOutputStream(filename, false); ! dumpXml(destination); ! destination.close(); } --- 567,590 ---- * @throws RrdException Thrown in case of JRobin related error. */ public synchronized void dumpXml(String filename) throws IOException, RrdException { ! OutputStream outputStream = null; ! try { ! outputStream = new FileOutputStream(filename, false); ! dumpXml(outputStream); ! } ! finally { ! if(outputStream != null) { ! outputStream.close(); ! } ! } ! } ! ! /** ! * This method is just an alias for {@link #dumpXml(String) dumpXml(String)} method. ! * @throws IOException Thrown in case of I/O related error ! * @throws RrdException Thrown in case of JRobin specific error ! */ ! public synchronized void exportXml(String filename) throws IOException, RrdException { ! dumpXml(filename); } Index: RrdFile.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdFile.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdFile.java 27 Nov 2003 10:22:58 -0000 1.3 --- RrdFile.java 19 Feb 2004 12:23:57 -0000 1.4 *************** *** 142,146 **** return filePath; } ! /** * Returns canonical path to RRD file on disk. --- 142,146 ---- return filePath; } ! /** * Returns canonical path to RRD file on disk. |