|
From: <sa...@us...> - 2003-09-29 11:25:31
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv10847/jrobin/core
Modified Files:
RrdDb.java Util.java XmlReader.java XmlWriter.java
Log Message:
More optimized XML import/export methods.
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/RrdDb.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RrdDb.java 24 Sep 2003 11:32:24 -0000 1.4
--- RrdDb.java 29 Sep 2003 11:25:05 -0000 1.5
***************
*** 191,194 ****
--- 191,196 ----
archives[i] = new Archive(this, reader, i);
}
+ // XMLReader is a rather huge DOM tree, release memory ASAP
+ reader = null;
// finalize
finalizeSetup(true);
***************
*** 513,517 ****
public synchronized void dumpXml(String filename) throws IOException, RrdException {
! OutputStream destination = new BufferedOutputStream(new FileOutputStream(filename, false));
dumpXml(destination);
destination.close();
--- 515,519 ----
public synchronized void dumpXml(String filename) throws IOException, RrdException {
! OutputStream destination = new FileOutputStream(filename, false);
dumpXml(destination);
destination.close();
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Util.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Util.java 24 Sep 2003 11:32:24 -0000 1.3
--- Util.java 29 Sep 2003 11:25:05 -0000 1.4
***************
*** 110,112 ****
--- 110,124 ----
}
+ public static double parseDouble(String valueStr) {
+ double value;
+ try {
+ value = Double.parseDouble(valueStr);
+ }
+ catch(NumberFormatException nfe) {
+ // Arne Vandamme fixed bug on UNKN value from Windows
+ value = Double.NaN;
+ }
+ return value;
+ }
+
}
Index: XmlReader.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/XmlReader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** XmlReader.java 4 Sep 2003 13:26:41 -0000 1.1
--- XmlReader.java 29 Sep 2003 11:25:05 -0000 1.2
***************
*** 29,45 ****
import org.xml.sax.SAXException;
! import javax.xml.parsers.DocumentBuilder;
! import javax.xml.parsers.DocumentBuilderFactory;
! import javax.xml.parsers.FactoryConfigurationError;
! import javax.xml.parsers.ParserConfigurationException;
! import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
class XmlReader {
! private Document doc;
private Element root;
! private Node[] dsNodes;
! private Node[] arcNodes;
public XmlReader(String xmlFilePath) throws IOException, RrdException {
--- 29,41 ----
import org.xml.sax.SAXException;
! import javax.xml.parsers.*;
import java.io.IOException;
+ import java.io.File;
import java.util.ArrayList;
class XmlReader {
!
private Element root;
! private Node[] dsNodes, arcNodes;
public XmlReader(String xmlFilePath) throws IOException, RrdException {
***************
*** 49,53 ****
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
! doc = builder.parse(new File(xmlFilePath));
root = doc.getDocumentElement();
dsNodes = getChildNodes(root, "ds");
--- 45,49 ----
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
! Document doc = builder.parse(new File(xmlFilePath));
root = doc.getDocumentElement();
dsNodes = getChildNodes(root, "ds");
***************
*** 151,159 ****
Node[] vNodes = getChildNodes(rows[i], "v");
Node vNode = vNodes[dsIndex];
! values[i] = Double.parseDouble(vNode.getFirstChild().getNodeValue().trim());
}
return values;
}
static Node[] getChildNodes(Node parentNode, String childName) {
ArrayList nodes = new ArrayList();
--- 147,157 ----
Node[] vNodes = getChildNodes(rows[i], "v");
Node vNode = vNodes[dsIndex];
! values[i] = Util.parseDouble(vNode.getFirstChild().getNodeValue().trim());
}
return values;
}
+ // utility functions for DOM tree traversing
+
static Node[] getChildNodes(Node parentNode, String childName) {
ArrayList nodes = new ArrayList();
***************
*** 198,210 ****
static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException {
- // Arne Vandamme fixed bug on UNKN value from Windows
String valueStr = getChildValue(parentNode, childName);
! try {
! return Double.parseDouble(valueStr);
! }
! catch (NumberFormatException nfe) {
! return Double.NaN;
! }
}
!
! }
--- 196,201 ----
static double getChildValueAsDouble(Node parentNode, String childName) throws RrdException {
String valueStr = getChildValue(parentNode, childName);
! return Util.parseDouble(valueStr);
}
! }
\ No newline at end of file
Index: XmlWriter.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/XmlWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** XmlWriter.java 24 Sep 2003 11:32:24 -0000 1.1
--- XmlWriter.java 29 Sep 2003 11:25:05 -0000 1.2
***************
*** 25,29 ****
import java.io.OutputStream;
import java.io.PrintWriter;
! import java.util.ArrayList;
import java.text.DecimalFormat;
--- 25,29 ----
import java.io.OutputStream;
import java.io.PrintWriter;
! import java.util.Stack;
import java.text.DecimalFormat;
***************
*** 47,51 ****
void closeTag() {
! String tag = openTags.pop();
indent.setLength(indent.length() - INDENT_STR.length());
writer.println(indent + "</" + tag + ">");
--- 47,51 ----
void closeTag() {
! String tag = (String) openTags.pop();
indent.setLength(indent.length() - INDENT_STR.length());
writer.println(indent + "</" + tag + ">");
***************
*** 87,108 ****
void writeComment(Object comment) {
writer.println(indent + "<!-- " + comment + " -->");
- }
-
- private class Stack {
- private ArrayList stack = new ArrayList();
-
- void push(String tag) {
- stack.add(tag);
- }
-
- String pop() {
- int last = stack.size() - 1;
- if(last >= 0) {
- String tag = (String) stack.get(last);
- stack.remove(last);
- return tag;
- }
- return null;
- }
}
}
--- 87,90 ----
|