From: Tarus B. <ta...@us...> - 2006-12-21 18:03:14
|
Update of /cvsroot/jrobin/src/org/jrobin/convertor In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/convertor Modified Files: Convertor.java Log Message: Adding the new 1.5.4 code Index: Convertor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/convertor/Convertor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Convertor.java 9 Nov 2004 12:33:13 -0000 1.6 --- Convertor.java 21 Dec 2006 18:02:41 -0000 1.7 *************** *** 1,115 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.convertor; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! ! import java.io.*; ! import java.text.DecimalFormat; ! import java.util.Date; ! ! class Convertor { ! private static final String FACTORY_NAME = "FILE"; ! private static final String SUFFIX = ".jrb"; ! private static final DecimalFormat secondsFormatter = new DecimalFormat("##0.000"); ! private static final DecimalFormat countFormatter = new DecimalFormat("0000"); ! ! private String[] files; ! private int totalCount, badCount, goodCount; ! ! private Convertor(String[] files) { ! try { ! RrdDb.setDefaultFactory(FACTORY_NAME); ! } ! catch (RrdException e) { ! e.printStackTrace(); ! System.exit(-1); ! } ! this.files = files; ! } ! ! private void convertAll() { ! Date t1 = new Date(); ! final String ruler = "======================================================================="; ! println(ruler); ! println("Converting RRDTool files to JRobin native format."); ! println("Original RRDTool files will not be modified in any way"); ! println("JRobin files created during the process will have a " + SUFFIX + " suffix"); ! println(ruler); ! for(int i = 0; i < files.length; i++) { ! convertFile(files[i]); ! } ! println(ruler); ! println("Finished: " + totalCount + " total, " + ! goodCount + " OK, " + badCount + " failed"); ! Date t2 = new Date(); ! double secs = (t2.getTime() - t1.getTime()) / 1000.0; ! println("Conversion took " + secondsFormatter.format(secs) + " sec"); ! if(totalCount > 0) { ! double avgSec = secs / totalCount; ! println("Average per-file conversion time: " + secondsFormatter.format(avgSec) + " sec"); ! } ! } ! ! private void convertFile(String path) { ! long start = System.currentTimeMillis(); ! totalCount++; ! try { ! File rrdFile = new File(path); ! print(countFormatter.format(totalCount) + "/" + countFormatter.format(files.length) + ! " " + rrdFile.getName() + " "); ! String sourcePath = rrdFile.getCanonicalPath(); ! String destPath = sourcePath + SUFFIX; ! RrdDb rrd = new RrdDb(destPath, RrdDb.PREFIX_RRDTool + sourcePath); ! rrd.close(); ! goodCount++; ! double seconds = (System.currentTimeMillis() - start) / 1000.0; ! println("[OK, " + secondsFormatter.format(seconds) + " sec]"); ! } catch (Exception e) { ! badCount++; ! println("[" + e + "]"); ! } ! } ! ! private final static void println(String msg) { ! System.out.println(msg); ! } ! ! private final static void print(String msg) { ! System.out.print(msg); ! } ! ! public static void main(String[] args) { ! if(args.length == 0) { ! println("Usage : java -jar convertor.jar <RRD file pattern> ..."); ! println("Example: java -jar convertor.jar files/*.rrd"); ! System.exit(1); ! } ! Convertor c = new Convertor(args); ! c.convertAll(); ! } ! } --- 1,133 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.convertor; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! ! import java.io.*; ! import java.text.DecimalFormat; ! import java.util.Date; ! ! /** ! * Simple utility class to convert RRD files created with RRDTool 1.0.x to ! * JRobin's native RRD format. Conversion process is quite fast. ! */ ! public class Convertor { ! private static final String FACTORY_NAME = "FILE"; ! private static final String SUFFIX = ".jrb"; ! private static final DecimalFormat secondsFormatter = new DecimalFormat("##0.000"); ! private static final DecimalFormat countFormatter = new DecimalFormat("0000"); ! ! private String[] files; ! private int totalCount, badCount, goodCount; ! ! private Convertor(String[] files) { ! try { ! RrdDb.setDefaultFactory(FACTORY_NAME); ! } ! catch (RrdException e) { ! e.printStackTrace(); ! System.exit(-1); ! } ! this.files = files; ! } ! ! private void convertAll() { ! Date t1 = new Date(); ! final String ruler = "======================================================================="; ! println(ruler); ! println("Converting RRDTool files to JRobin native format."); ! println("Original RRDTool files will not be modified in any way"); ! println("JRobin files created during the process will have a " + SUFFIX + " suffix"); ! println(ruler); ! for (String file : files) { ! convertFile(file); ! } ! println(ruler); ! println("Finished: " + totalCount + " total, " + ! goodCount + " OK, " + badCount + " failed"); ! Date t2 = new Date(); ! double secs = (t2.getTime() - t1.getTime()) / 1000.0; ! println("Conversion took " + secondsFormatter.format(secs) + " sec"); ! if (totalCount > 0) { ! double avgSec = secs / totalCount; ! println("Average per-file conversion time: " + secondsFormatter.format(avgSec) + " sec"); ! } ! } ! ! private void convertFile(String path) { ! long start = System.currentTimeMillis(); ! totalCount++; ! try { ! File rrdFile = new File(path); ! print(countFormatter.format(totalCount) + "/" + countFormatter.format(files.length) + ! " " + rrdFile.getName() + " "); ! String sourcePath = rrdFile.getCanonicalPath(); ! String destPath = sourcePath + SUFFIX; ! RrdDb rrd = new RrdDb(destPath, RrdDb.PREFIX_RRDTool + sourcePath); ! rrd.close(); ! goodCount++; ! double seconds = (System.currentTimeMillis() - start) / 1000.0; ! println("[OK, " + secondsFormatter.format(seconds) + " sec]"); ! } ! catch (Exception e) { ! badCount++; ! println("[" + e + "]"); ! } ! } ! ! private static void println(String msg) { ! System.out.println(msg); ! } ! ! private static void print(String msg) { ! System.out.print(msg); ! } ! ! /** ! * <p>To convert RRD files created with RRDTool use the following syntax:</p> ! * <pre> ! * java -cp jrobin-{version} org.jrobin.convertor.Convert [path to RRD file(s)] ! * <pre> ! * <p>For example:</p> ! * <pre> ! * java -cp jrobin-{version} org.jrobin.convertor.Convert rrdtool/files/*.rrd ! * </pre> ! * <p>...and enjoy the show.</p> ! * ! * @param args ! */ ! public static void main(String[] args) { ! if (args.length == 0) { ! println("Usage : java -jar convertor.jar <RRD file pattern> ..."); ! println("Example: java -jar convertor.jar files/*.rrd"); ! System.exit(1); ! } ! Convertor c = new Convertor(args); ! c.convertAll(); ! } ! } |