Update of /cvsroot/jrobin/src/org/jrobin/convertor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27887/org/jrobin/convertor
Modified Files:
Convertor.java
Log Message:
Nice utility to convert RRD files from RRDTool format to JRobin native format
Index: Convertor.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/convertor/Convertor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Convertor.java 27 Jan 2004 10:49:42 -0000 1.1
--- Convertor.java 19 Feb 2004 10:46:08 -0000 1.2
***************
*** 24,28 ****
private void convert() {
! println("Conversion started");
long start = System.currentTimeMillis();
if(!workingDirectory.endsWith(SEPARATOR)) {
--- 24,31 ----
private void convert() {
! println("Converting RRDTool files to JRobin native format");
! println("Converted files will be placed in the same directory, with " +
! suffix + " suffix appended");
! println("==========================================");
long start = System.currentTimeMillis();
if(!workingDirectory.endsWith(SEPARATOR)) {
***************
*** 43,46 ****
--- 46,50 ----
File[] files = parent.listFiles(filter);
for(int i = 0; i < files.length; i++) {
+ print("[" + i + "/" + files.length + "] ");
convertFile(files[i]);
}
***************
*** 62,78 ****
private long convertFile(File rrdFile) {
long start = System.currentTimeMillis();
try {
String sourcePath = rrdFile.getCanonicalPath();
! String xmlPath = sourcePath + ".xml";
! String destPath = sourcePath + suffix;
print(rrdFile.getName() + " ");
- // dump to XML file
xmlDump(sourcePath, xmlPath);
- // create RRD file from XML file
RrdDb rrd = new RrdDb(destPath, xmlPath);
rrd.close();
rrd = null;
System.gc();
- new File(xmlPath).delete();
okCount++;
long elapsed = System.currentTimeMillis() - start;
--- 66,80 ----
private long convertFile(File rrdFile) {
long start = System.currentTimeMillis();
+ String xmlPath = null, destPath = null;
try {
String sourcePath = rrdFile.getCanonicalPath();
! xmlPath = sourcePath + ".xml";
! destPath = sourcePath + suffix;
print(rrdFile.getName() + " ");
xmlDump(sourcePath, xmlPath);
RrdDb rrd = new RrdDb(destPath, xmlPath);
rrd.close();
rrd = null;
System.gc();
okCount++;
long elapsed = System.currentTimeMillis() - start;
***************
*** 80,91 ****
--- 82,105 ----
return elapsed;
} catch (IOException e) {
+ removeFile(destPath);
badCount++;
println("[IO ERROR]");
return -1;
} catch (RrdException e) {
+ removeFile(destPath);
badCount++;
println("[RRD ERROR]");
return -2;
}
+ finally {
+ removeFile(xmlPath);
+ }
+ }
+
+ private static boolean removeFile(String filePath) {
+ if(filePath != null) {
+ return new File(filePath).delete();
+ }
+ return true;
}
***************
*** 94,99 ****
Process p = RUNTIME.exec(cmd);
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmlPath, false));
! readStream(p.getInputStream(), outStream);
! readStream(p.getErrorStream(), null);
try {
p.waitFor();
--- 108,113 ----
Process p = RUNTIME.exec(cmd);
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmlPath, false));
! transportStream(p.getInputStream(), outStream);
! transportStream(p.getErrorStream(), null);
try {
p.waitFor();
***************
*** 102,107 ****
// NOP
}
- outStream.flush();
- outStream.close();
}
--- 116,119 ----
***************
*** 125,133 ****
}
! private static void readStream(InputStream in, OutputStream out) throws IOException {
! int b;
! while((b = in.read()) != -1) {
if(out != null) {
! out.write(b);
}
}
--- 137,154 ----
}
! private static void transportStream(InputStream in, OutputStream out) throws IOException {
! try {
! int b;
! while((b = in.read()) != -1) {
! if(out != null) {
! out.write(b);
! }
! }
! }
! finally {
! in.close();
if(out != null) {
! out.flush();
! out.close();
}
}
|